Optimizing away deletion of null pointers with g++

Oleg Endo oleg.endo@t-online.de
Wed Aug 16 14:40:00 GMT 2017

On Wed, 2017-08-16 at 13:30 +0200, Paolo Carlini wrote:
> I didn't understand why we don't already handle the easy case:
> constexpr int* ptr = nullptr;
> delete ptr;

What about overriding the global delete operator with some user defined
implementation?  Is there something in the C++ standard that says the
invocation can be completely omitted, i.e. on which side of the call
the nullptr check is being done?

One possible use case could be overriding the global delete operator to
count the number of invocations, incl. for nullptr.  Not sure how
useful that is though.


More information about the Gcc mailing list