From Jason Turner

[dcl.init.aggr]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp3k9ovq7v/{from.md → to.md} +30 -25
tmp/tmp3k9ovq7v/{from.md → to.md} RENAMED
@@ -3,12 +3,13 @@
3
  An *aggregate* is an array or a class [[class]] with
4
 
5
  - no user-declared or inherited constructors [[class.ctor]],
6
  - no private or protected direct non-static data members
7
  [[class.access]],
8
- - no virtual functions [[class.virtual]], and
9
- - no virtual, private, or protected base classes [[class.mi]].
 
10
 
11
  [*Note 1*: Aggregate initialization does not allow accessing protected
12
  and private base class’ members or constructors. — *end note*]
13
 
14
  The *elements* of an aggregate are:
@@ -21,29 +22,29 @@ The *elements* of an aggregate are:
21
  When an aggregate is initialized by an initializer list as specified in 
22
  [[dcl.init.list]], the elements of the initializer list are taken as
23
  initializers for the elements of the aggregate. The *explicitly
24
  initialized elements* of the aggregate are determined as follows:
25
 
26
- - If the initializer list is a *designated-initializer-list*, the
27
- aggregate shall be of class type, the *identifier* in each
28
- *designator* shall name a direct non-static data member of the class,
29
- and the explicitly initialized elements of the aggregate are the
30
- elements that are, or contain, those members.
31
- - If the initializer list is an *initializer-list*, the explicitly
32
- initialized elements of the aggregate are the first n elements of the
33
- aggregate, where n is the number of elements in the initializer list.
 
34
  - Otherwise, the initializer list must be `{}`, and there are no
35
  explicitly initialized elements.
36
 
37
  For each explicitly initialized element:
38
 
39
- - If the element is an anonymous union object and the initializer list
40
- is a *designated-initializer-list*, the anonymous union object is
41
- initialized by the *designated-initializer-list* `{ `*D*` }`, where
42
- *D* is the *designated-initializer-clause* naming a member of the
43
- anonymous union object. There shall be only one such
44
- *designated-initializer-clause*.
45
  \[*Example 1*:
46
  ``` cpp
47
  struct C {
48
  union {
49
  int a;
@@ -60,11 +61,15 @@ For each explicitly initialized element:
60
  *brace-or-equal-initializer* of the corresponding
61
  *designated-initializer-clause*. If that initializer is of the form
62
  *assignment-expression* or `= `*assignment-expression* and a narrowing
63
  conversion [[dcl.init.list]] is required to convert the expression,
64
  the program is ill-formed.
65
- \[*Note 2*: If an initializer is itself an initializer list, the
 
 
 
 
66
  element is list-initialized, which will result in a recursive
67
  application of the rules in this subclause if the element is an
68
  aggregate. — *end note*]
69
  \[*Example 2*:
70
  ``` cpp
@@ -160,11 +165,11 @@ expression not enclosed in braces, as described in  [[dcl.init]].
160
 
161
  The destructor for each element of class type is potentially invoked
162
  [[class.dtor]] from the context where the aggregate initialization
163
  occurs.
164
 
165
- [*Note 3*: This provision ensures that destructors can be called for
166
  fully-constructed subobjects in case an exception is thrown
167
  [[except.ctor]]. — *end note*]
168
 
169
  An array of unknown bound initialized with a brace-enclosed
170
  *initializer-list* containing `n` *initializer-clause*s is defined as
@@ -182,11 +187,11 @@ elements since no size was specified and there are three initializers.
182
  — *end example*]
183
 
184
  An array of unknown bound shall not be initialized with an empty
185
  *braced-init-list* `{}`.[^6]
186
 
187
- [*Note 4*:
188
 
189
  A default member initializer does not determine the bound for a member
190
  array of unknown bound. Since the default member initializer is ignored
191
  if a suitable *mem-initializer* is present [[class.base.init]], the
192
  default member initializer is not considered to initialize the array of
@@ -202,11 +207,11 @@ struct S {
202
 
203
  — *end example*]
204
 
205
  — *end note*]
206
 
207
- [*Note 5*:
208
 
209
  Static data members, non-static data members of anonymous union members,
210
  and unnamed bit-fields are not considered elements of the aggregate.
211
 
212
  [*Example 6*:
@@ -289,11 +294,11 @@ struct A {
289
  }; // Initialization not required for A::s3 because A::i3 is also not initialized
290
  ```
291
 
292
  — *end example*]
293
 
294
- When initializing a multi-dimensional array, the *initializer-clause*s
295
  initialize the elements with the last (rightmost) index of the array
296
  varying the fastest [[dcl.array]].
297
 
298
  [*Example 10*:
299
 
@@ -363,11 +368,11 @@ the element with an *assignment-expression*. If the
363
  *assignment-expression* can initialize an element, the element is
364
  initialized. Otherwise, if the element is itself a subaggregate, brace
365
  elision is assumed and the *assignment-expression* is considered for the
366
  initialization of the first element of the subaggregate.
367
 
368
- [*Note 6*: As specified above, brace elision cannot apply to
369
  subaggregates with no elements; an *initializer-clause* for the entire
370
  subobject is required. — *end note*]
371
 
372
  [*Example 12*:
373
 
@@ -388,16 +393,16 @@ Braces are elided around the *initializer-clause* for `b.a1.i`. `b.a1.i`
388
  is initialized with 4, `b.a2` is initialized with `a`, `b.z` is
389
  initialized with whatever `a.operator int()` returns.
390
 
391
  — *end example*]
392
 
393
- [*Note 7*: An aggregate array or an aggregate class may contain
394
  elements of a class type with a user-declared constructor
395
  [[class.ctor]]. Initialization of these aggregate objects is described
396
  in  [[class.expl.init]]. — *end note*]
397
 
398
- [*Note 8*: Whether the initialization of aggregates with static storage
399
  duration is static or dynamic is specified in  [[basic.start.static]],
400
  [[basic.start.dynamic]], and  [[stmt.dcl]]. — *end note*]
401
 
402
  When a union is initialized with an initializer list, there shall not be
403
  more than one explicitly initialized element.
@@ -415,9 +420,9 @@ u f = { .b = "asdf" };
415
  u g = { .a = 1, .b = "asdf" }; // error
416
  ```
417
 
418
  — *end example*]
419
 
420
- [*Note 9*: As described above, the braces around the
421
  *initializer-clause* for a union member can be omitted if the union is a
422
  member of another aggregate. — *end note*]
423
 
 
3
  An *aggregate* is an array or a class [[class]] with
4
 
5
  - no user-declared or inherited constructors [[class.ctor]],
6
  - no private or protected direct non-static data members
7
  [[class.access]],
8
+ - no private or protected direct base classes [[class.access.base]], and
9
+ - no virtual functions [[class.virtual]] or virtual base classes
10
+ [[class.mi]].
11
 
12
  [*Note 1*: Aggregate initialization does not allow accessing protected
13
  and private base class’ members or constructors. — *end note*]
14
 
15
  The *elements* of an aggregate are:
 
22
  When an aggregate is initialized by an initializer list as specified in 
23
  [[dcl.init.list]], the elements of the initializer list are taken as
24
  initializers for the elements of the aggregate. The *explicitly
25
  initialized elements* of the aggregate are determined as follows:
26
 
27
+ - If the initializer list is a brace-enclosed
28
+ *designated-initializer-list*, the aggregate shall be of class type,
29
+ the *identifier* in each *designator* shall name a direct non-static
30
+ data member of the class, and the explicitly initialized elements of
31
+ the aggregate are the elements that are, or contain, those members.
32
+ - If the initializer list is a brace-enclosed *initializer-list*, the
33
+ explicitly initialized elements of the aggregate are the first n
34
+ elements of the aggregate, where n is the number of elements in the
35
+ initializer list.
36
  - Otherwise, the initializer list must be `{}`, and there are no
37
  explicitly initialized elements.
38
 
39
  For each explicitly initialized element:
40
 
41
+ - If the element is an anonymous union member and the initializer list
42
+ is a brace-enclosed *designated-initializer-list*, the element is
43
+ initialized by the *braced-init-list* `{ `*D*` }`, where *D* is the
44
+ *designated-initializer-clause* naming a member of the anonymous union
45
+ member. There shall be only one such *designated-initializer-clause*.
 
46
  \[*Example 1*:
47
  ``` cpp
48
  struct C {
49
  union {
50
  int a;
 
61
  *brace-or-equal-initializer* of the corresponding
62
  *designated-initializer-clause*. If that initializer is of the form
63
  *assignment-expression* or `= `*assignment-expression* and a narrowing
64
  conversion [[dcl.init.list]] is required to convert the expression,
65
  the program is ill-formed.
66
+ \[*Note 2*: If the initialization is by
67
+ *designated-initializer-clause*, its form determines whether
68
+ copy-initialization or direct-initialization is
69
+ performed. — *end note*]
70
+ \[*Note 3*: If an initializer is itself an initializer list, the
71
  element is list-initialized, which will result in a recursive
72
  application of the rules in this subclause if the element is an
73
  aggregate. — *end note*]
74
  \[*Example 2*:
75
  ``` cpp
 
165
 
166
  The destructor for each element of class type is potentially invoked
167
  [[class.dtor]] from the context where the aggregate initialization
168
  occurs.
169
 
170
+ [*Note 4*: This provision ensures that destructors can be called for
171
  fully-constructed subobjects in case an exception is thrown
172
  [[except.ctor]]. — *end note*]
173
 
174
  An array of unknown bound initialized with a brace-enclosed
175
  *initializer-list* containing `n` *initializer-clause*s is defined as
 
187
  — *end example*]
188
 
189
  An array of unknown bound shall not be initialized with an empty
190
  *braced-init-list* `{}`.[^6]
191
 
192
+ [*Note 5*:
193
 
194
  A default member initializer does not determine the bound for a member
195
  array of unknown bound. Since the default member initializer is ignored
196
  if a suitable *mem-initializer* is present [[class.base.init]], the
197
  default member initializer is not considered to initialize the array of
 
207
 
208
  — *end example*]
209
 
210
  — *end note*]
211
 
212
+ [*Note 6*:
213
 
214
  Static data members, non-static data members of anonymous union members,
215
  and unnamed bit-fields are not considered elements of the aggregate.
216
 
217
  [*Example 6*:
 
294
  }; // Initialization not required for A::s3 because A::i3 is also not initialized
295
  ```
296
 
297
  — *end example*]
298
 
299
+ When initializing a multidimensional array, the *initializer-clause*s
300
  initialize the elements with the last (rightmost) index of the array
301
  varying the fastest [[dcl.array]].
302
 
303
  [*Example 10*:
304
 
 
368
  *assignment-expression* can initialize an element, the element is
369
  initialized. Otherwise, if the element is itself a subaggregate, brace
370
  elision is assumed and the *assignment-expression* is considered for the
371
  initialization of the first element of the subaggregate.
372
 
373
+ [*Note 7*: As specified above, brace elision cannot apply to
374
  subaggregates with no elements; an *initializer-clause* for the entire
375
  subobject is required. — *end note*]
376
 
377
  [*Example 12*:
378
 
 
393
  is initialized with 4, `b.a2` is initialized with `a`, `b.z` is
394
  initialized with whatever `a.operator int()` returns.
395
 
396
  — *end example*]
397
 
398
+ [*Note 8*: An aggregate array or an aggregate class can contain
399
  elements of a class type with a user-declared constructor
400
  [[class.ctor]]. Initialization of these aggregate objects is described
401
  in  [[class.expl.init]]. — *end note*]
402
 
403
+ [*Note 9*: Whether the initialization of aggregates with static storage
404
  duration is static or dynamic is specified in  [[basic.start.static]],
405
  [[basic.start.dynamic]], and  [[stmt.dcl]]. — *end note*]
406
 
407
  When a union is initialized with an initializer list, there shall not be
408
  more than one explicitly initialized element.
 
420
  u g = { .a = 1, .b = "asdf" }; // error
421
  ```
422
 
423
  — *end example*]
424
 
425
+ [*Note 10*: As described above, the braces around the
426
  *initializer-clause* for a union member can be omitted if the union is a
427
  member of another aggregate. — *end note*]
428