Title
Evaluation order in initializer-lists used in aggregate initialization
Status
c++11
Section
9.4.2 [dcl.init.aggr]
Submitter
Scott Meyers

Created on 2010-02-09.00:00:00 last changed 131 months ago

Messages

Date: 2011-03-15.00:00:00

[Voted into the WP at the March, 2011 meeting.]

Date: 2011-01-15.00:00:00

Proposed resolution (January, 2011):

  1. Delete 9.4.2 [dcl.init.aggr] paragraph 17:

  2. The full-expressions in an initializer-clause are evaluated in the order in which they appear.
  3. Insert the following as a new paragraph between paragraphs 3 and 4 of 9.4.5 [dcl.init.list]

  4. Within the initializer-list of a braced-init-list, the initializer-clauses, including any that result from pack expansions (13.7.4 [temp.variadic]), are evaluated in the order in which they appear. That is, every value computation and side effect associated with a given initializer-clause is sequenced before every value computation and side effect associated with any initializer-clause that follows it in the comma-separated list of the initializer-list. [Note: This evaluation ordering holds regardless of the semantics of the initialization; for example, it applies when the elements of the initializer-list are interpreted as arguments of a constructor call, even though ordinarily there are no sequencing constraints on the arguments of a call. —end note]
Date: 2010-11-15.00:00:00

Notes from the November, 2010 meeting:

The CWG favored guaranteeing the order of evaluation of initializer-clauses appearing in a braced-init-list, regardless of whether the braced-init-list is an aggregate initialization or constructor call.

Date: 2010-02-09.00:00:00

The ordering imposed by 9.4.2 [dcl.init.aggr] paragraph 17 applies only to “the full-expressions in an initializer-clause” (i.e., what follows an = in an aggregate initializer); this leaves unspecified the order in which the expressions in an initializer-list (the term used by the braced-init-list form of initializer, with no =) are evaluated.

History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3348
2011-04-10 00:00:00adminsetstatus: tentatively ready -> fdis
2011-02-28 00:00:00adminsetmessages: + msg3232
2011-02-28 00:00:00adminsetstatus: drafting -> tentatively ready
2010-11-29 00:00:00adminsetmessages: + msg3120
2010-11-29 00:00:00adminsetstatus: open -> drafting
2010-02-09 00:00:00admincreate