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


2721. When exactly is storage reused?

Section:6.8.4  [basic.life]    Status:CD7    Submitter:Richard Smith    Date:2023-03-23

[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:

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:
  struct S {    int m;  };  void f() {    S x{1};    new(&x) S(x.m);  //undefined behavior  }
-- end example ]



[8]ページ先頭

©2009-2026 Movatter.jp