From Jason Turner

[dcl.init.aggr]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpmgv59dtx/{from.md → to.md} +20 -17
tmp/tmpmgv59dtx/{from.md → to.md} RENAMED
@@ -1,13 +1,12 @@
1
  ### Aggregates <a id="dcl.init.aggr">[[dcl.init.aggr]]</a>
2
 
3
  An *aggregate* is an array or a class (Clause  [[class]]) with no
4
- user-provided constructors ([[class.ctor]]), no
5
- *brace-or-equal-initializer*s for non-static data members (
6
- [[class.mem]]), no private or protected non-static data members (Clause 
7
- [[class.access]]), no base classes (Clause  [[class.derived]]), and no
8
- virtual functions ([[class.virtual]]).
9
 
10
  When an aggregate is initialized by an initializer list, as specified
11
  in  [[dcl.init.list]], the elements of the initializer list are taken as
12
  initializers for the members of the aggregate, in increasing subscript
13
  or member order. Each member is copy-initialized from the corresponding
@@ -43,11 +42,11 @@ int x[] = { 1, 3, 5 };
43
  ```
44
 
45
  declares and initializes `x` as a one-dimensional array that has three
46
  elements since no size was specified and there are three initializers.
47
  An empty initializer list `{}` shall not be used as the
48
- *initializer-clause * for an array of unknown bound.[^16]
49
 
50
  Static data members and anonymous bit-fields are not considered members
51
  of the class for purposes of aggregate initialization.
52
 
53
  ``` cpp
@@ -74,20 +73,30 @@ char cv[4] = { 'a', 's', 'd', 'f', 0 }; // error
74
 
75
  is ill-formed.
76
 
77
  If there are fewer *initializer-clause*s in the list than there are
78
  members in the aggregate, then each member not explicitly initialized
79
- shall be initialized from an empty initializer list (
 
80
  [[dcl.init.list]]).
81
 
82
  ``` cpp
83
- struct S { int a; const char* b; int c; };
84
  S ss = { 1, "asdf" };
85
  ```
86
 
87
- initializes `ss.a` with 1, `ss.b` with `"asdf"`, and `ss.c` with the
88
- value of an expression of the form `int()`, that is, `0`.
 
 
 
 
 
 
 
 
 
89
 
90
  If an aggregate class `C` contains a subaggregate member `m` that has no
91
  members for purposes of aggregate initialization, the
92
  *initializer-clause* for `m` shall not be omitted from an
93
  *initializer-list* for an object of type `C` unless the
@@ -132,17 +141,11 @@ float y[4][3] = {
132
  ```
133
 
134
  initializes the first column of `y` (regarded as a two-dimensional
135
  array) and leaves the rest zero.
136
 
137
- In a declaration of the form
138
-
139
- ``` cpp
140
- T x = { a };
141
- ```
142
-
143
- braces can be elided in an *initializer-list* as follows.[^17] If the
144
  *initializer-list* begins with a left brace, then the succeeding
145
  comma-separated list of *initializer-clause*s initializes the members of
146
  a subaggregate; it is erroneous for there to be more
147
  *initializer-clause*s than members. If, however, the *initializer-list*
148
  for a subaggregate does not begin with a left brace, then only enough
 
1
  ### Aggregates <a id="dcl.init.aggr">[[dcl.init.aggr]]</a>
2
 
3
  An *aggregate* is an array or a class (Clause  [[class]]) with no
4
+ user-provided constructors ([[class.ctor]]), no private or protected
5
+ non-static data members (Clause  [[class.access]]), no base classes
6
+ (Clause  [[class.derived]]), and no virtual functions (
7
+ [[class.virtual]]).
 
8
 
9
  When an aggregate is initialized by an initializer list, as specified
10
  in  [[dcl.init.list]], the elements of the initializer list are taken as
11
  initializers for the members of the aggregate, in increasing subscript
12
  or member order. Each member is copy-initialized from the corresponding
 
42
  ```
43
 
44
  declares and initializes `x` as a one-dimensional array that has three
45
  elements since no size was specified and there are three initializers.
46
  An empty initializer list `{}` shall not be used as the
47
+ *initializer-clause * for an array of unknown bound.[^15]
48
 
49
  Static data members and anonymous bit-fields are not considered members
50
  of the class for purposes of aggregate initialization.
51
 
52
  ``` cpp
 
73
 
74
  is ill-formed.
75
 
76
  If there are fewer *initializer-clause*s in the list than there are
77
  members in the aggregate, then each member not explicitly initialized
78
+ shall be initialized from its *brace-or-equal-initializer* or, if there
79
+ is no *brace-or-equal-initializer*, from an empty initializer list (
80
  [[dcl.init.list]]).
81
 
82
  ``` cpp
83
+ struct S { int a; const char* b; int c; int d = b[a]; };
84
  S ss = { 1, "asdf" };
85
  ```
86
 
87
+ initializes `ss.a` with 1, `ss.b` with `"asdf"`, `ss.c` with the value
88
+ of an expression of the form `int{}` (that is, `0`), and `ss.d` with the
89
+ value of `ss.b[ss.a]` (that is, `'s'`), and in
90
+
91
+ ``` cpp
92
+ struct X { int i, j, k = 42; };
93
+ X a[] = { 1, 2, 3, 4, 5, 6 };
94
+ X b[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
95
+ ```
96
+
97
+ `a` and `b` have the same value
98
 
99
  If an aggregate class `C` contains a subaggregate member `m` that has no
100
  members for purposes of aggregate initialization, the
101
  *initializer-clause* for `m` shall not be omitted from an
102
  *initializer-list* for an object of type `C` unless the
 
141
  ```
142
 
143
  initializes the first column of `y` (regarded as a two-dimensional
144
  array) and leaves the rest zero.
145
 
146
+ Braces can be elided in an *initializer-list* as follows. If the
 
 
 
 
 
 
147
  *initializer-list* begins with a left brace, then the succeeding
148
  comma-separated list of *initializer-clause*s initializes the members of
149
  a subaggregate; it is erroneous for there to be more
150
  *initializer-clause*s than members. If, however, the *initializer-list*
151
  for a subaggregate does not begin with a left brace, then only enough