Title
Array delete expression with no array cookie
Status
open
Section
7.6.2.9 [expr.delete]
Submitter
Blacktea Hamburger

Created on 2022-08-22.00:00:00 last changed 3 weeks ago

Messages

Date: 2022-09-05.08:32:31

Suggested resolution:

Change in 7.6.2.9 [expr.delete] paragraph 2 as follows:

... In an array delete expression, the value of the operand of delete may be a null pointer value or a pointer value that resulted from a previous array new-expression whose allocation function was not a non-allocating form (17.7.3.4 [new.delete.placement]). [ Footnote: ... ] If not, the behavior is undefined.
Date: 2022-09-11.18:10:12

Consider:

char *p = static_cast<char*>(operator new[](2));
p = new (p) char[2];  // #1
delete[] p;           // #2

Subclause 7.6.2.8 [expr.new] paragraph 16 specifies:

... When a new-expression calls an allocation function and that allocation has not been extended, the new-expression passes the amount of space requested to the allocation function as the first argument of type std::size_t. That argument shall be no less than the size of the object being created; it may be greater than the size of the object being created only if the object is an array and the allocation function is not a non-allocating form (17.7.3.4 [new.delete.placement]). ...

Subclause 7.6.2.9 [expr.delete] paragraph 2 specifies:

... In an array delete expression, the value of the operand of delete may be a null pointer value or a pointer value that resulted from a previous array new-expression. [ Footnote: ... ] If not, the behavior is undefined.

The non-allocating form of the new-expression at #1 is constrained not to place an array cookie at the start of the array. Yet, the array delete appears to be expected to divine that fact.

History
Date User Action Args
2022-09-05 08:32:31adminsetmessages: + msg6927
2022-08-22 00:00:00admincreate