I know that delete
ing a null pointer is a no-op:
In either alternative, if the value of the operand of delete is the null pointer the operation has no effect.
(C++ Standard5.3.5 [expr.delete] p2
)
And also that deleting a void*
pointer is undefined behaviour because the destructor can't be called as there are no objects of type void
:
In the first alternative (
delete object
), the value of the operand of delete shall be a pointer to a non-array object or a pointer to a sub-object representing a base class of such an object. If not, the behavior is undefined.
(C++ Standard5.3.5 [expr.delete] p2
)
Now, normally I take it that things that are listed first overrule things that are listed later on, but what about null void*
pointer as the following?
void* p = 0;
delete p; // UB or well-defined?
See Question&Answers more detail:os