From Jason Turner

[class.base.init]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpc98t3ant/{from.md → to.md} +28 -28
tmp/tmpc98t3ant/{from.md → to.md} RENAMED
@@ -66,11 +66,11 @@ direct non-virtual base class and an inherited virtual base class, the
66
 
67
  ``` cpp
68
  struct A { A(); };
69
  struct B: public virtual A { };
70
  struct C: public A, public B { C(); };
71
- C::C(): A() { } // ill-formed: which A?
72
  ```
73
 
74
  — *end example*]
75
 
76
  A *ctor-initializer* may initialize a variant member of the
@@ -123,12 +123,12 @@ D d(10);
123
  ```
124
 
125
  — *end example*]
126
 
127
  [*Note 2*: The initialization performed by each *mem-initializer*
128
- constitutes a full-expression ([[intro.execution]]). Any expression in
129
- a *mem-initializer* is evaluated as part of the full-expression that
130
  performs the initialization. — *end note*]
131
 
132
  A *mem-initializer* where the *mem-initializer-id* denotes a virtual
133
  base class is ignored during execution of a constructor of any class
134
  that is not the most derived class.
@@ -151,27 +151,27 @@ 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*
159
  or
160
  - the constructor’s class is not a union, and, if the entity is a
161
  member of an anonymous union, no other member of that union is
162
  designated by a *mem-initializer-id*,
163
 
164
  the entity is initialized from its default member initializer as
165
  specified in  [[dcl.init]];
166
- - otherwise, if the entity is an anonymous union or a variant member (
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
171
- derived class, thus its constructors never initialize virtual base
172
- classes, 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
 
@@ -243,22 +243,22 @@ A a2(1); // OK, unfortunately
243
  ```
244
 
245
  — *end example*]
246
 
247
  In a non-delegating constructor, the destructor for each potentially
248
- constructed subobject of class type is potentially invoked (
249
- [[class.dtor]]).
250
 
251
  [*Note 5*: This provision ensures that destructors can be called for
252
- fully-constructed subobjects in case an exception is thrown (
253
- [[except.ctor]]). — *end note*]
254
 
255
  In a non-delegating constructor, initialization proceeds in the
256
  following order:
257
 
258
- - First, and only for the constructor of the most derived class (
259
- [[intro.object]]), virtual base classes are initialized in the order
260
  they appear on a depth-first left-to-right traversal of the directed
261
  acyclic graph of base classes, where “left-to-right” is the order of
262
  appearance of the base classes in the derived class
263
  *base-specifier-list*.
264
  - Then, direct base classes are initialized in declaration order as they
@@ -338,16 +338,16 @@ 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]]).
345
- However, if these operations are performed in a *ctor-initializer* (or
346
- in a function called directly or indirectly from a *ctor-initializer*)
347
- before all the *mem-initializer*s for base classes have completed, the
348
- program has undefined behavior.
349
 
350
  [*Example 11*:
351
 
352
  ``` cpp
353
  class A {
@@ -357,11 +357,11 @@ public:
357
 
358
  class B : public A {
359
  int j;
360
  public:
361
  int f();
362
- B() : A(f()), // undefined: calls member function but base A not yet initialized
363
  j(f()) { } // well-defined: bases are all initialized
364
  };
365
 
366
  class C {
367
  public:
@@ -369,24 +369,24 @@ public:
369
  };
370
 
371
  class D : public B, C {
372
  int i;
373
  public:
374
- D() : C(f()), // undefined: calls member function but base C not yet initialized
375
  i(f()) { } // well-defined: bases are all initialized
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 (
387
- [[temp.variadic]]) that initializes the base classes specified by a pack
388
  expansion in the *base-specifier-list* for the class.
389
 
390
  [*Example 12*:
391
 
392
  ``` cpp
 
66
 
67
  ``` cpp
68
  struct A { A(); };
69
  struct B: public virtual A { };
70
  struct C: public A, public B { C(); };
71
+ C::C(): A() { } // error: which A?
72
  ```
73
 
74
  — *end example*]
75
 
76
  A *ctor-initializer* may initialize a variant member of the
 
123
  ```
124
 
125
  — *end example*]
126
 
127
  [*Note 2*: The initialization performed by each *mem-initializer*
128
+ constitutes a full-expression [[intro.execution]]. Any expression in a
129
+ *mem-initializer* is evaluated as part of the full-expression that
130
  performs the initialization. — *end note*]
131
 
132
  A *mem-initializer* where the *mem-initializer-id* denotes a virtual
133
  base class is ignored during execution of a constructor of any class
134
  that is not the most derived class.
 
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*
159
  or
160
  - the constructor’s class is not a union, and, if the entity is a
161
  member of an anonymous union, no other member of that union is
162
  designated by a *mem-initializer-id*,
163
 
164
  the entity is initialized from its default member initializer as
165
  specified in  [[dcl.init]];
166
+ - otherwise, if the entity is an anonymous union or a variant member
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
 
 
243
  ```
244
 
245
  — *end example*]
246
 
247
  In a non-delegating constructor, the destructor for each potentially
248
+ constructed subobject of class type is potentially invoked
249
+ [[class.dtor]].
250
 
251
  [*Note 5*: This provision ensures that destructors can be called for
252
+ fully-constructed subobjects in case an exception is thrown
253
+ [[except.ctor]]. — *end note*]
254
 
255
  In a non-delegating constructor, initialization proceeds in the
256
  following order:
257
 
258
+ - First, and only for the constructor of the most derived class
259
+ [[intro.object]], virtual base classes are initialized in the order
260
  they appear on a depth-first left-to-right traversal of the directed
261
  acyclic graph of base classes, where “left-to-right” is the order of
262
  appearance of the base classes in the derived class
263
  *base-specifier-list*.
264
  - Then, direct base classes are initialized in declaration order as they
 
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
346
+ function called directly or indirectly from a *ctor-initializer*) before
347
+ all the *mem-initializer*s for base classes have completed, the program
348
+ has undefined behavior.
349
 
350
  [*Example 11*:
351
 
352
  ``` cpp
353
  class A {
 
357
 
358
  class B : public A {
359
  int j;
360
  public:
361
  int f();
362
+ B() : A(f()), // undefined behavior: calls member function but base A not yet initialized
363
  j(f()) { } // well-defined: bases are all initialized
364
  };
365
 
366
  class C {
367
  public:
 
369
  };
370
 
371
  class D : public B, C {
372
  int i;
373
  public:
374
+ D() : C(f()), // undefined behavior: calls member function but base C not yet initialized
375
  i(f()) { } // well-defined: bases are all initialized
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
387
+ [[temp.variadic]] that initializes the base classes specified by a pack
388
  expansion in the *base-specifier-list* for the class.
389
 
390
  [*Example 12*:
391
 
392
  ``` cpp