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

2024-04-18


1419. Evaluation order in aggregate initialization

Section: 9.4.5  [dcl.init.list]     Status: NAD     Submitter: Jason Merrill     Date: 2011-11-22

Issue 1030 clarified that elements of an initializer-list are evaluated in the order they are written, but does that also apply to implied expressions? That is, given:

    struct A { A(); ~A(); };
    struct B { B(int, const A& = A()); ~B(); };
    struct C { B b1, b2; };
    int main() { C{1,2}; }

Do we know that the first B is constructed before the second A? I suppose that's what we want, even though it complicates exception region nesting since the As need to live longer than the B subobject cleanups.

Rationale (October, 2012):

Because this is an expression, not a declaration, the As live until the end of the full-expression.