On 16 August 2017 at 15:27, Oleg Endo wrote: > 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.
Users can replace the deallocation function "operator delete" but this is the delete operator ... a subtly different thing. Anyway, the standard says: "If the value of the operand of the delete-expression is a null pointer value, it is unspecified whether a deallocation function will be called as described above." So it's permitted to omit the call to operator delete.