https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109442
--- Comment #20 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jan Hubicka from comment #19) > Similar argument can IMO be used for eliding unused memory allocations. It > is kind of up to std::vector implementation on how many > allocations/deallocations it does, right? It's up to std::allocator, which is not required to call operator new every time memory is needed. > So we need a way to annotate the new/delete calls in the standard library as > safe for such optimizations (i.e. implement clang's > __bulitin_operator_new/delete?) Yes, see PR 110137. > How clang manages to optimize this out without additional hinting? It supports __builtin_operator_{new,delete} and libstdc++ uses that when compiled with clang.