In c++03 it is pretty clear that deleting a null pointer has no effect. In fact, in §5.3.5/2 explicitly stated that:
In any alternative, if the value of the delete operand is a null pointer, the operation has no effect.
However, in the current project for c++0x this suggestion seems to be missing. In the rest of the project, I could only find suggestions about what would happen if the operand of the delete expression is not a null pointer constant. Removes a null pointer still defined in c++0x , and if so, where?
Notes:
There is significant indirect evidence that they are still clearly defined.
Firstly, in §5.3.5/2 there are two sentences which state that
In the first alternative (delete object), the value of the delete operand may be the value of a null pointer, ...
and
In the second alternative (delete array), the value of the delete operand may be the value of a null pointer or ...
They say that the operand is allowed to be zero, but they themselves do not determine what will happen if it is.
Secondly, changing the value of delete 0 is a serious violation of the changes, and the standards committee is unlikely to change this particular change. Moreover, the mention of this is not a change in the compatibility application (Appendix C) of the c++0x project. However, Appendix C is an information section, so this has nothing to do with the interpretation of the standard.
On the other hand, the fact that deleting a null pointer is not required implies additional verification at runtime. In a lot of code, an operand can never be null, so this runtime check contradicts the principle of a zero premium. Perhaps the committee simply decided to change the behavior to bring standard C ++ into line with the stated design goals of the language.
c ++ null language-lawyer delete-operator
Mankarse Jul 18 2018-11-11T00: 00Z
source share