Search code examples
c++language-lawyerc++17delete-operatornullptr

What C++17 standard say about calling delete on nullptr?


C++03 Standard say's:

5.3.5 Delete

[...] In either alternative, if the value of the operand of delete is the null pointer the operation has no effect.[...]

char *p = nullptr;
delete p; //no effect

It means, it is valid to delete null pointer in c++.

What C++17 standard say about calling delete on nullptr pointer?


Solution

  • Yes it is valid, and it results in a noop. reference

    If expression evaluates to a null pointer value, no destructors are called, and the deallocation function is not called.