Movatterモバイル変換


[0]ホーム

URL:


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

2025-12-20


2624. Array delete expression with no array cookie

Section:7.6.2.9  [expr.delete]    Status:C++23    Submitter:Blacktea Hamburger    Date:2022-08-22

[Accepted as a DR at the November, 2022 meeting.]

Consider:

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

Subclause 7.6.2.8 [expr.new] paragraph 16 specifies:

... When anew-expression calls an allocation function and thatallocation has not been extended, thenew-expression passes theamount of space requested to the allocation function as the firstargument of type std::size_t. That argument shall be no less than thesize of the object being created; it may be greater than the size ofthe object being created only if the object is an array and theallocation 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 operandofdelete may be a null pointer value or a pointer value thatresulted from a previous arraynew-expression. [ Footnote:... ] If not, the behavior is undefined.

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

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 operandofdelete may be a null pointer value or a pointer value thatresulted from a previous arraynew-expressionwhoseallocation function was not a non-allocating form(17.6.3.4 [new.delete.placement]). [ Footnote: ... ] If not, thebehavior is undefined.



[8]ページ先頭

©2009-2026 Movatter.jp