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


201. Order of destruction of temporaries in initializers

Section:6.8.7  [class.temporary]    Status:CD1    Submitter:Alan Nash    Date:31 Jan 2000

[Moved to DR at 4/01 meeting.]

According to 6.8.7 [class.temporary]paragraph 4, an expression appearing as the initializer in an objectdefinition constitutes a context "in which temporaries are destroyedat a different point than the end of the full-expression." It goes onto say that the temporary containing the value of the expressionpersists until after the initialization is complete (see alsoissue 117). This seems to presumethat the end of the full-expression is a point earlier than thecompletion of the initialization.

However, according to6.10.1 [intro.execution]paragraphs 12-13, thefull-expression in such cases is, in fact, the entire initialization.If this is the case, the behavior described for temporaries in aninitializer expression is simply the normal behavior of temporaries inany expression, and treating it as an exception to the general rule isboth incorrect and confusing.

Proposed resolution (04/01):

[Note: this proposal also addressesissue 124.]

  1. Add to the end of 6.10.1 [intro.execution] paragraph 12:

    If the initializer for an object orsub-object is a full-expression, the initialization ofthe object or sub-object (e.g., by calling a constructoror copying an expression value) is considered to be partof the full-expression.
  2. Replace 6.8.7 [class.temporary] paragraph 4 with:

    There are two contexts in which temporaries aredestroyed at a different point than the end of thefull-expression. The first context is when adefault constructor is called to initialize anelement of an array. If the constructor has oneor more default arguments, any temporaries createdin the default argument expressions are destroyedimmediately after return from the constructor.



[8]ページ先頭

©2009-2026 Movatter.jp