https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94295
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Richard Smith from comment #2) > (In reply to Marc Glisse from comment #1) > > (In reply to Richard Smith from comment #0) > > > The C++ language rules do not permit optimization (eg, deletion) of direct > > > calls to 'operator new' and 'operator delete'. > > > > I thought that was considered a bug? > > No, it's intentional: if the user directly calls '::operator new(42)' and > they've replaced that function, the replacement function is guaranteed to be > called. In this regard, 'operator new' is just a regular function with a > funny name. > > To be clear, the implicit call to 'operator new' produced by, say, 'new int' > *is* optimizable, but a direct explicit call to 'operator new(sizeof(int))' > is not. > > > Gcc does optimize those, like it does malloc/free... > > That sounds like non-conforming behavior. PR 23383 is where part of the discussion was done. In fact GCC implements the optimization without the builtin: https://gcc.gnu.org/legacy-ml/gcc-patches/2019-07/msg00136.html