Member initializers and aggregates

ISO/IEC JTC1 SC22 WG21 N3653 - 2013-04-17

Ville Voutilainen, ville.voutilainen@gmail.com
Richard Smith, richard@metafoo.co.uk

Proposed Wording

Change in 8.5.1 (dcl.init.aggr) paragraph 1:

An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no brace-or-equal-initializers for non-static data members (9.2), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).
Change in 8.5.1 paragraph 7:
If there are fewer initializer-clauses in the list than there are members in the aggregate, then each member not explicitly initialized shall be initialized from its brace-or-equal-initializer or, if there is no brace-or-equal-initializer, from an empty initializer list (8.5.4). [ Example:
  struct S { int a; const char* b; int c; int d = b[a]; };
  S ss = { 1, "asdf" };
initializes ss.a with 1, ss.b with "asdf", and 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'), and in
  struct X { int i, j, k = 42; };
  X a[] = { 1, 2, 3, 4, 5, 6 };
  X b[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
a and b have the same value
. -end example ]