No, don't check for null. The standard says that delete (T*)0;
is valid. It will just complicate your code for no benefits. If operator delete
is overloaded it's better to check for null in the implementation of the operator. Just saves code lines and bugs.
EDIT: This answer was accepted and upvoted, yet, in my opinion, it was not very informative. There is one missing piece in all answers here, and, for conscience sake, let me add this last piece here.
The standard actually says in [basic.stc.dynamic], at least since C++03:
Any allocation and/or deallocation functions defined in a C++ program, including the default versions in the library, shall conform to the semantics specified in 3.7.4.1 and 3.7.4.2.
Where the referenced sections, as well as some other places in the standard listed in other answers, say that the semantics of passing a null pointer are a no-op.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…