Why isn't this unused variable optimised away?

后端 未结 4 1727
情深已故
情深已故 2021-02-06 21:47

I played around with Godbolt\'s CompilerExplorer. I wanted to see how good certain optimizations are. My minimum working example is:

#include 

int         


        
4条回答
  •  佛祖请我去吃肉
    2021-02-06 22:34

    As the comments note, operator new can be replaced. This can happen in any Translation Unit. Optimizing a program for the case it's not replaced therefore requires Whole-Program Analysis. And if it is replaced, you have to call it of course.

    Whether the default operator new is a library I/O call is unspecified. That matters, because library I/O calls are observable and therefore they can't be optimized out either.

提交回复
热议问题