Can the compiler optimize from heap to stack allocation?
问题 As far as compiler optimizations go, is it legal and/or possible to change a heap allocation to a stack allocation? Or would that break the as-if rule? For example, say this is the original version of the code { Foo* f = new Foo(); f->do_something(); delete f; } Would a compiler be able to change this to the following { Foo f{}; f.do_something(); } I wouldn't think so, because that would have implications if the original version was relying on things like custom allocators. Does the standard