for a class, the direct base classes in declaration order,
followed by the direct non-static data members ([class.mem])
that are not members of an anonymous union, in declaration order.
When an aggregate is initialized by an initializer list
as specified in [dcl.init.list],
the elements of the initializer list are taken as initializers
for the elements of the aggregate.
If the initializer list is
a brace-enclosed designated-initializer-list,
the aggregate shall be of class type,
the identifier in each designator
shall name a direct non-static data member of the class, and
the explicitly initialized elements of the aggregate
are the elements that are, or contain, those members.
If the initializer list is a brace-enclosed initializer-list,
the explicitly initialized elements of the aggregate
are those for which an element of the initializer list
appertains to the aggregate element or to a subobject thereof (see below).
If that initializer is of the form
=assignment-expression
and
a narrowing conversion ([dcl.init.list]) is required
to convert the expression, the program is ill-formed.
Otherwise,
the aggregate element is copy-initialized
from a brace-enclosed initializer-list
consisting of all of the initializer-clauses
that appertain to subobjects of the aggregate element,
in the order of appearance.
If an initializer is itself an initializer list,
the element is list-initialized, which will result in a recursive application
of the rules in this subclause if the element is an aggregate.
struct S {int a; constchar* b; int c; int d = b[a]; };
S ss ={1, "asdf"};
initializes
ss.a
with 1,
ss.b
with "asdf",
ss.c
with the value of an expression of the form
int{}
(that is, 0), and ss.d with the value of ss.b[ss.a]
(that is, 's').
The destructor for each element of class type
other than an anonymous union member
is potentially invoked ([class.dtor])
from the context where the aggregate initialization occurs.
The number of elements ([dcl.array]) in an array of unknown bound
initialized with a brace-enclosed initializer-list
is the number of explicitly initialized elements of the array.
int x[]={1, 3, 5};
declares and initializes
x
as a one-dimensional array that has three elements
since no size was specified and there are three initializers.
A default member initializer does not determine the bound for a member
array of unknown bound.
Since the default member initializer is
ignored if a suitable mem-initializer is present ([class.base.init]),
the default member initializer is not
considered to initialize the array of unknown bound.
[Example 6: struct S {int y[]={0}; // error: non-static data member of incomplete type};
— end example]
Static data members,
non-static data members of anonymous union members,
and
unnamed bit-fields
are not considered elements of the aggregate.
[Example 7: struct A {int i;
staticint s;
int j;
int:17;
int k;
} a ={1, 2, 3};
Here, the second initializer 2 initializes
a.j
and not the static data member
A::s, and the third initializer 3 initializes a.k
and not the unnamed bit-field before it.
If a member has a default member initializer
and a potentially-evaluated subexpression thereof is an aggregate
initialization that would use that default member initializer,
the program is ill-formed.
[Example 8: struct A;
extern A a;
struct A {const A& a1 { A{a,a}}; // OKconst A& a2 { A{}}; // error};
A a{a,a