This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 110b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2023-01-15


599. Deleting a null function pointer

Section: 7.6.2.9  [expr.delete]     Status: CD2     Submitter: Martin Sebor     Date: 3 October 2006

[Voted into WP at July, 2009 meeting.]

The requirements for the operand of the delete operators are given in 7.6.2.9 [expr.delete] paragraph 2:

In either alternative, the value of the operand of delete may be a null pointer value. If it is not a null pointer value, 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 subobject (6.7.2 [intro.object]) representing a base class of such an object (11.7 [class.derived]). If not, the behavior is undefined. In the second alternative (delete array), the value of the operand of delete shall be the pointer value which resulted from a previous array new-expression. If not, the behavior is undefined.

There are no restrictions on the type of a null pointer, only on a pointer that is not null. That seems wrong.

Proposed resolution (June, 2008):

Change 7.6.2.9 [expr.delete] paragraph 1 as follows:

...The operand shall have a pointer to object type, or a class type having a single non-explicit conversion function (11.4.8.3 [class.conv.fct]) to a pointer to object type...

Proposed resolution (September, 2008):

  1. Change 7.6.2.9 [expr.delete] paragraph 1 as follows:

  2. ...The operand shall have a pointer to object type, or a class type having a single non-explicit conversion function (12.3.2) to a pointer to object type. [Footnote: This implies that an object cannot be deleted using a pointer of type void* because void is not an object type. —end footnote] ...
  3. Delete the footnote at the end of 7.6.2.9 [expr.delete] paragraph 3:

  4. ...if the dynamic type of the object to be deleted differs from its static type, the behavior is undefined. [Footnote: This implies that an object cannot be deleted using a pointer of type void* because there are no objects of type void. —end footnote]