From Jason Turner

[class.base.init]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpjvzc7h1k/{from.md → to.md} +18 -23
tmp/tmpjvzc7h1k/{from.md → to.md} RENAMED
@@ -25,20 +25,18 @@ mem-initializer:
25
  mem-initializer-id:
26
  class-or-decltype
27
  identifier
28
  ```
29
 
30
- In a *mem-initializer-id* an initial unqualified *identifier* is looked
31
- up in the scope of the constructor’s class and, if not found in that
32
- scope, it is looked up in the scope containing the constructor’s
33
- definition.
34
 
35
  [*Note 1*: If the constructor’s class contains a member with the same
36
  name as a direct or virtual base class of the class, a
37
  *mem-initializer-id* naming the member or base class and composed of a
38
  single identifier refers to the class member. A *mem-initializer-id* for
39
- the hidden base class may be specified using a qualified
40
  name. — *end note*]
41
 
42
  Unless the *mem-initializer-id* names the constructor’s class, a
43
  non-static data member of the constructor’s class, or a direct or
44
  virtual base of that class, the *mem-initializer* is ill-formed.
@@ -57,11 +55,11 @@ C::C(): global_A() { } // mem-initializer for base A
57
  ```
58
 
59
  — *end example*]
60
 
61
  If a *mem-initializer-id* is ambiguous because it designates both a
62
- direct non-virtual base class and an inherited virtual base class, the
63
  *mem-initializer* is ill-formed.
64
 
65
  [*Example 2*:
66
 
67
  ``` cpp
@@ -145,14 +143,15 @@ struct A {
145
  };
146
  ```
147
 
148
  — *end example*]
149
 
150
- In a non-delegating constructor, if a given potentially constructed
151
- subobject is not designated by a *mem-initializer-id* (including the
152
- case where there is no *mem-initializer-list* because the constructor
153
- has no *ctor-initializer*), then
 
154
 
155
  - if the entity is a non-static data member that has a default member
156
  initializer [[class.mem]] and either
157
  - the constructor’s class is a union [[class.union]], and no other
158
  variant member of that union is designated by a *mem-initializer-id*
@@ -167,11 +166,11 @@ has no *ctor-initializer*), then
167
  [[class.union.anon]], no initialization is performed;
168
  - otherwise, the entity is default-initialized [[dcl.init]].
169
 
170
  [*Note 3*: An abstract class [[class.abstract]] is never a most derived
171
  class, thus its constructors never initialize virtual base classes,
172
- therefore the corresponding *mem-initializer*s may be
173
  omitted. — *end note*]
174
 
175
  An attempt to initialize more than one non-static data member of a union
176
  renders the program ill-formed.
177
 
@@ -193,14 +192,14 @@ struct B {
193
  B(int);
194
  };
195
 
196
  struct C {
197
  C() { } // initializes members as follows:
198
- A a; // OK: calls A::A()
199
  const B b; // error: B has no default constructor
200
- int i; // OK: i has indeterminate value
201
- int j = 5; // OK: j has the value 5
202
  };
203
  ```
204
 
205
  — *end example*]
206
 
@@ -306,13 +305,14 @@ B b(3); // use V()
306
  C c(4); // use V()
307
  ```
308
 
309
  — *end example*]
310
 
311
- Names in the *expression-list* or *braced-init-list* of a
312
- *mem-initializer* are evaluated in the scope of the constructor for
313
- which the *mem-initializer* is specified.
 
314
 
315
  [*Example 10*:
316
 
317
  ``` cpp
318
  class X {
@@ -331,15 +331,10 @@ of the constructor parameter `i`, initializes `X::i` with the value of
331
  the constructor parameter `i`, and initializes `X::j` with the value of
332
  `X::i`; this takes place each time an object of class `X` is created.
333
 
334
  — *end example*]
335
 
336
- [*Note 7*: Because the *mem-initializer* are evaluated in the scope of
337
- the constructor, the `this` pointer can be used in the *expression-list*
338
- of a *mem-initializer* to refer to the object being
339
- initialized. — *end note*]
340
-
341
  Member functions (including virtual member functions, [[class.virtual]])
342
  can be called for an object under construction. Similarly, an object
343
  under construction can be the operand of the `typeid` operator
344
  [[expr.typeid]] or of a `dynamic_cast` [[expr.dynamic.cast]]. However,
345
  if these operations are performed in a *ctor-initializer* (or in a
@@ -376,11 +371,11 @@ public:
376
  };
377
  ```
378
 
379
  — *end example*]
380
 
381
- [*Note 8*: [[class.cdtor]] describes the result of virtual function
382
  calls, `typeid` and `dynamic_cast`s during construction for the
383
  well-defined cases; that is, describes the polymorphic behavior of an
384
  object under construction. — *end note*]
385
 
386
  A *mem-initializer* followed by an ellipsis is a pack expansion
 
25
  mem-initializer-id:
26
  class-or-decltype
27
  identifier
28
  ```
29
 
30
+ Lookup for an unqualified name in a *mem-initializer-id* ignores the
31
+ constructor’s function parameter scope.
 
 
32
 
33
  [*Note 1*: If the constructor’s class contains a member with the same
34
  name as a direct or virtual base class of the class, a
35
  *mem-initializer-id* naming the member or base class and composed of a
36
  single identifier refers to the class member. A *mem-initializer-id* for
37
+ the hidden base class can be specified using a qualified
38
  name. — *end note*]
39
 
40
  Unless the *mem-initializer-id* names the constructor’s class, a
41
  non-static data member of the constructor’s class, or a direct or
42
  virtual base of that class, the *mem-initializer* is ill-formed.
 
55
  ```
56
 
57
  — *end example*]
58
 
59
  If a *mem-initializer-id* is ambiguous because it designates both a
60
+ direct non-virtual base class and an indirect virtual base class, the
61
  *mem-initializer* is ill-formed.
62
 
63
  [*Example 2*:
64
 
65
  ``` cpp
 
143
  };
144
  ```
145
 
146
  — *end example*]
147
 
148
+ In a non-delegating constructor other than an implicitly-defined
149
+ copy/move constructor [[class.copy.ctor]], if a given potentially
150
+ constructed subobject is not designated by a *mem-initializer-id*
151
+ (including the case where there is no *mem-initializer-list* because the
152
+ constructor has no *ctor-initializer*), then
153
 
154
  - if the entity is a non-static data member that has a default member
155
  initializer [[class.mem]] and either
156
  - the constructor’s class is a union [[class.union]], and no other
157
  variant member of that union is designated by a *mem-initializer-id*
 
166
  [[class.union.anon]], no initialization is performed;
167
  - otherwise, the entity is default-initialized [[dcl.init]].
168
 
169
  [*Note 3*: An abstract class [[class.abstract]] is never a most derived
170
  class, thus its constructors never initialize virtual base classes,
171
+ therefore the corresponding *mem-initializer*s can be
172
  omitted. — *end note*]
173
 
174
  An attempt to initialize more than one non-static data member of a union
175
  renders the program ill-formed.
176
 
 
192
  B(int);
193
  };
194
 
195
  struct C {
196
  C() { } // initializes members as follows:
197
+ A a; // OK, calls A::A()
198
  const B b; // error: B has no default constructor
199
+ int i; // OK, i has indeterminate value
200
+ int j = 5; // OK, j has the value 5
201
  };
202
  ```
203
 
204
  — *end example*]
205
 
 
305
  C c(4); // use V()
306
  ```
307
 
308
  — *end example*]
309
 
310
+ [*Note 7*: The *expression-list* or *braced-init-list* of a
311
+ *mem-initializer* is in the function parameter scope of the constructor
312
+ and can use `this` to refer to the object being
313
+ initialized. — *end note*]
314
 
315
  [*Example 10*:
316
 
317
  ``` cpp
318
  class X {
 
331
  the constructor parameter `i`, and initializes `X::j` with the value of
332
  `X::i`; this takes place each time an object of class `X` is created.
333
 
334
  — *end example*]
335
 
 
 
 
 
 
336
  Member functions (including virtual member functions, [[class.virtual]])
337
  can be called for an object under construction. Similarly, an object
338
  under construction can be the operand of the `typeid` operator
339
  [[expr.typeid]] or of a `dynamic_cast` [[expr.dynamic.cast]]. However,
340
  if these operations are performed in a *ctor-initializer* (or in a
 
371
  };
372
  ```
373
 
374
  — *end example*]
375
 
376
+ [*Note 8*: [[class.cdtor]] describes the results of virtual function
377
  calls, `typeid` and `dynamic_cast`s during construction for the
378
  well-defined cases; that is, describes the polymorphic behavior of an
379
  object under construction. — *end note*]
380
 
381
  A *mem-initializer* followed by an ellipsis is a pack expansion