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

后端 未结 7 544
灰色年华
灰色年华 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:46

    just tried this example on compiler explorer, and at -O3 the mov is not generated when the return value is not used.

    https://gcc.godbolt.org/z/v5WGPr

提交回复
热议问题