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
[Accepted as a DR at the June, 2023 meeting.]
Subclause 6.8.4 [basic.life] bullet 1.5 specifies:
The lifetime of an object o of type T ends when:
- if T is a non-class type, the object is destroyed, or
- if T is a class type, the destructor call starts, or
- the storage which the object occupies is released, or is reused byan object that is not nested within o(6.8.2 [intro.object]).
Consider the expressionnew (p) T(x). Does the lifetimeof*p end whenp is returned from the allocationfunction, beforex is evaluated? Or does the lifetime endwhen the constructor body starts executing, afterx isevaluated?
The second option is conceivable for initialization by constructorand non-class types; for aggregate initialization, the first optionmust be used, because evaluation ofx directly initializes apart of the resulting object. The first option is simpler toimplement for constant evaluation.
Proposed resolution (approved by CWG 2023-05-12):
Change in 6.8.4 [basic.life] paragraph 1 as follows:
The lifetime of an object o of type T ends when:When evaluating anew-expression, storage is consideredreused after it is returned from the allocation function, but beforethe evaluation of thenew-initializer(7.6.2.8 [expr.new]). [ Example:
- if T is a non-class type, the object is destroyed, or
- if T is a class type, the destructor call starts, or
- the storage which the object occupies is released, or is reused byan object that is not nested within o(6.8.2 [intro.object]).
struct S { int m; }; void f() { S x{1}; new(&x) S(x.m); //undefined behavior }-- end example ]