Created on 2022-08-22.00:00:00 last changed 17 months ago
Proposed resolution (approved by CWG 2022-10-07):
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.6.3.4 [new.delete.placement]). [ Footnote: ... ] If not, the behavior is undefined.
[Accepted as a DR at the November, 2022 meeting.]
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.6.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 |
2023-07-16 13:00:43 | admin | set | status: open -> c++23 |
2023-07-16 13:00:43 | admin | set | status: drwp -> open |
2023-02-18 18:43:04 | admin | set | status: dr -> drwp |
2022-11-25 05:14:04 | admin | set | status: ready -> dr |
2022-10-07 20:32:13 | admin | set | status: open -> ready |
2022-09-05 08:32:31 | admin | set | messages: + msg6927 |
2022-08-22 00:00:00 | admin | create |