tmp/tmpu4ddwukw/{from.md → to.md}
RENAMED
|
@@ -43,13 +43,12 @@ complex d = sqrt(b,c); // call sqrt(complex,complex)
|
|
| 43 |
complex e; // initialize by a call of
|
| 44 |
// complex()
|
| 45 |
complex f = 3; // construct complex(3) using
|
| 46 |
// complex(double)
|
| 47 |
// copy/move it into f
|
| 48 |
-
complex g = { 1, 2 }; //
|
| 49 |
-
//
|
| 50 |
-
// and copy/move it into g
|
| 51 |
```
|
| 52 |
|
| 53 |
overloading of the assignment operator ([[over.ass]]) has no effect on
|
| 54 |
initialization.
|
| 55 |
|
|
@@ -100,11 +99,11 @@ ctor-initializer:
|
|
| 100 |
```
|
| 101 |
|
| 102 |
``` bnf
|
| 103 |
mem-initializer-list:
|
| 104 |
mem-initializer '...'ₒₚₜ
|
| 105 |
-
mem-initializer ',' mem-initializer-list
|
| 106 |
```
|
| 107 |
|
| 108 |
``` bnf
|
| 109 |
mem-initializer:
|
| 110 |
mem-initializer-id '(' expression-listₒₚₜ ')'
|
|
@@ -202,31 +201,39 @@ full-expression. Any expression in a *mem-initializer* is evaluated as
|
|
| 202 |
part of the full-expression that performs the initialization. A
|
| 203 |
*mem-initializer* where the *mem-initializer-id* denotes a virtual base
|
| 204 |
class is ignored during execution of a constructor of any class that is
|
| 205 |
not the most derived class.
|
| 206 |
|
| 207 |
-
In a non-delegating constructor, if a given
|
| 208 |
-
|
| 209 |
case where there is no *mem-initializer-list* because the constructor
|
| 210 |
-
has no *ctor-initializer*)
|
| 211 |
-
an abstract class ([[class.abstract]]), then
|
| 212 |
|
| 213 |
- if the entity is a non-static data member that has a
|
| 214 |
-
*brace-or-equal-initializer*
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
- otherwise, the entity is default-initialized ([[dcl.init]]).
|
| 219 |
|
| 220 |
An abstract class ([[class.abstract]]) is never a most derived class,
|
| 221 |
thus its constructors never initialize virtual base classes, therefore
|
| 222 |
the corresponding *mem-initializer*s may be omitted. An attempt to
|
| 223 |
initialize more than one non-static data member of a union renders the
|
| 224 |
-
program ill-formed. After the call to a constructor for class `X`
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
| 228 |
|
| 229 |
``` cpp
|
| 230 |
struct A {
|
| 231 |
A();
|
| 232 |
};
|
|
@@ -259,10 +266,16 @@ struct A {
|
|
| 259 |
|
| 260 |
the `A(int)` constructor will simply initialize `i` to the value of
|
| 261 |
`arg`, and the side effects in `i`’s *brace-or-equal-initializer* will
|
| 262 |
not take place.
|
| 263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
In a non-delegating constructor, initialization proceeds in the
|
| 265 |
following order:
|
| 266 |
|
| 267 |
- First, and only for the constructor of the most derived class (
|
| 268 |
[[intro.object]]), virtual base classes are initialized in the order
|
|
|
|
| 43 |
complex e; // initialize by a call of
|
| 44 |
// complex()
|
| 45 |
complex f = 3; // construct complex(3) using
|
| 46 |
// complex(double)
|
| 47 |
// copy/move it into f
|
| 48 |
+
complex g = { 1, 2 }; // initialize by a call of
|
| 49 |
+
// complex(double, double)
|
|
|
|
| 50 |
```
|
| 51 |
|
| 52 |
overloading of the assignment operator ([[over.ass]]) has no effect on
|
| 53 |
initialization.
|
| 54 |
|
|
|
|
| 99 |
```
|
| 100 |
|
| 101 |
``` bnf
|
| 102 |
mem-initializer-list:
|
| 103 |
mem-initializer '...'ₒₚₜ
|
| 104 |
+
mem-initializer '...'ₒₚₜ ',' mem-initializer-list
|
| 105 |
```
|
| 106 |
|
| 107 |
``` bnf
|
| 108 |
mem-initializer:
|
| 109 |
mem-initializer-id '(' expression-listₒₚₜ ')'
|
|
|
|
| 201 |
part of the full-expression that performs the initialization. A
|
| 202 |
*mem-initializer* where the *mem-initializer-id* denotes a virtual base
|
| 203 |
class is ignored during execution of a constructor of any class that is
|
| 204 |
not the most derived class.
|
| 205 |
|
| 206 |
+
In a non-delegating constructor, if a given potentially constructed
|
| 207 |
+
subobject is not designated by a *mem-initializer-id* (including the
|
| 208 |
case where there is no *mem-initializer-list* because the constructor
|
| 209 |
+
has no *ctor-initializer*), then
|
|
|
|
| 210 |
|
| 211 |
- if the entity is a non-static data member that has a
|
| 212 |
+
*brace-or-equal-initializer* and either
|
| 213 |
+
- the constructor’s class is a union ([[class.union]]), and no other
|
| 214 |
+
variant member of that union is designated by a *mem-initializer-id*
|
| 215 |
+
or
|
| 216 |
+
- the constructor’s class is not a union, and, if the entity is a
|
| 217 |
+
member of an anonymous union, no other member of that union is
|
| 218 |
+
designated by a *mem-initializer-id*,
|
| 219 |
+
|
| 220 |
+
the entity is initialized as specified in [[dcl.init]];
|
| 221 |
+
- otherwise, if the entity is an anonymous union or a variant member (
|
| 222 |
+
[[class.union]]), no initialization is performed;
|
| 223 |
- otherwise, the entity is default-initialized ([[dcl.init]]).
|
| 224 |
|
| 225 |
An abstract class ([[class.abstract]]) is never a most derived class,
|
| 226 |
thus its constructors never initialize virtual base classes, therefore
|
| 227 |
the corresponding *mem-initializer*s may be omitted. An attempt to
|
| 228 |
initialize more than one non-static data member of a union renders the
|
| 229 |
+
program ill-formed. After the call to a constructor for class `X` for an
|
| 230 |
+
object with automatic or dynamic storage duration has completed, if the
|
| 231 |
+
constructor was not invoked as part of value-initialization and a member
|
| 232 |
+
of `X` is neither initialized nor given a value during execution of the
|
| 233 |
+
*compound-statement* of the body of the constructor, the member has an
|
| 234 |
+
indeterminate value.
|
| 235 |
|
| 236 |
``` cpp
|
| 237 |
struct A {
|
| 238 |
A();
|
| 239 |
};
|
|
|
|
| 266 |
|
| 267 |
the `A(int)` constructor will simply initialize `i` to the value of
|
| 268 |
`arg`, and the side effects in `i`’s *brace-or-equal-initializer* will
|
| 269 |
not take place.
|
| 270 |
|
| 271 |
+
In a non-delegating constructor, the destructor for each potentially
|
| 272 |
+
constructed subobject of class type is potentially invoked (
|
| 273 |
+
[[class.dtor]]). This provision ensures that destructors can be called
|
| 274 |
+
for fully-constructed sub-objects in case an exception is thrown (
|
| 275 |
+
[[except.ctor]]).
|
| 276 |
+
|
| 277 |
In a non-delegating constructor, initialization proceeds in the
|
| 278 |
following order:
|
| 279 |
|
| 280 |
- First, and only for the constructor of the most derived class (
|
| 281 |
[[intro.object]]), virtual base classes are initialized in the order
|