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

2024-03-20


1030. Evaluation order in initializer-lists used in aggregate initialization

Section: 9.4.2  [dcl.init.aggr]     Status: C++11     Submitter: Scott Meyers     Date: 2010-02-09

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

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.

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.

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]