Will the c++ compiler optimize away unused return value?

后端 未结 7 576
灰色年华
灰色年华 2021-01-18 19:24

If I have a function that returns an object, but this return value is never used by the caller, will the compiler optimize away the copy? (Possibly an always/sometimes/never

7条回答
  •  长情又很酷
    2021-01-18 19:58

    They most likely will if the optimization level causes them to inline the code. If not, they would have to generate two different translations of the same code to make it work, which could open up a lot of edge case problems.

提交回复
热议问题