tmp/tmp_8dyt6bj/{from.md → to.md}
RENAMED
|
@@ -56,12 +56,10 @@ cprint( complex(7.8,1.2) );
|
|
| 56 |
— *end example*]
|
| 57 |
|
| 58 |
[*Note 2*: For initialization of objects of class type see
|
| 59 |
[[class.init]]. — *end note*]
|
| 60 |
|
| 61 |
-
An object created in this way is unnamed.
|
| 62 |
-
|
| 63 |
[*Note 3*: [[class.temporary]] describes the lifetime of temporary
|
| 64 |
objects. — *end note*]
|
| 65 |
|
| 66 |
[*Note 4*: Explicit constructor calls do not yield lvalues, see
|
| 67 |
[[basic.lval]]. — *end note*]
|
|
@@ -87,79 +85,81 @@ A constructor shall not have an explicit object parameter [[dcl.fct]].
|
|
| 87 |
#### Default constructors <a id="class.default.ctor">[[class.default.ctor]]</a>
|
| 88 |
|
| 89 |
A *default constructor* for a class `X` is a constructor of class `X`
|
| 90 |
for which each parameter that is not a function parameter pack has a
|
| 91 |
default argument (including the case of a constructor with no
|
| 92 |
-
parameters). If there is no user-declared constructor
|
| 93 |
-
non-explicit constructor having no parameters
|
| 94 |
-
defaulted [[dcl.fct.def]]. An
|
| 95 |
-
an inline public member of
|
|
|
|
| 96 |
|
| 97 |
-
A defaulted default constructor for class `X` is defined as deleted if
|
| 98 |
|
| 99 |
-
- `X` is a union that has a variant member with a non-trivial default
|
| 100 |
-
constructor and no variant member of `X` has a default member
|
| 101 |
-
initializer,
|
| 102 |
-
- `X` is a non-union class that has a variant member `M` with a
|
| 103 |
-
non-trivial default constructor and no variant member of the anonymous
|
| 104 |
-
union containing `M` has a default member initializer,
|
| 105 |
- any non-static data member with no default member initializer
|
| 106 |
[[class.mem]] is of reference type,
|
| 107 |
-
- any non-variant non-static data member of
|
| 108 |
-
|
| 109 |
-
const-default-constructible
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
-
|
| 113 |
-
|
| 114 |
-
- any potentially constructed subobject, except for a non-static data
|
| 115 |
-
member with a *brace-or-equal-initializer*, has class type `M` (or
|
| 116 |
-
array thereof) and either `M` has no default constructor or overload
|
| 117 |
resolution [[over.match]] as applied to find `M`’s corresponding
|
| 118 |
-
constructor
|
| 119 |
-
|
| 120 |
-
- any potentially constructed subobject has
|
| 121 |
-
|
| 122 |
-
constructor
|
|
|
|
| 123 |
|
| 124 |
-
A default constructor is *trivial* if it is not
|
|
|
|
| 125 |
|
| 126 |
-
-
|
| 127 |
-
|
| 128 |
-
- no non-static data member of
|
| 129 |
-
|
| 130 |
-
- all the direct base classes of
|
| 131 |
-
|
| 132 |
-
-
|
| 133 |
-
type (or array thereof), each such
|
| 134 |
-
constructor.
|
| 135 |
|
| 136 |
Otherwise, the default constructor is *non-trivial*.
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
*compound-statement*. If that user-written default constructor would be
|
| 143 |
-
ill-formed, the program is ill-formed.
|
| 144 |
-
constructor
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
non-static data members are implicitly defined.
|
| 149 |
|
| 150 |
-
[*Note
|
| 151 |
specification [[except.spec]]. An explicitly-defaulted definition might
|
| 152 |
have an implicit exception specification, see
|
| 153 |
[[dcl.fct.def]]. — *end note*]
|
| 154 |
|
| 155 |
-
[*Note
|
| 156 |
class object when no initializer is specified [[dcl.init.general]]. Such
|
| 157 |
-
a default constructor
|
| 158 |
[[class.access]]. — *end note*]
|
| 159 |
|
| 160 |
-
[*Note
|
| 161 |
constructors for base classes and non-static data members are called and
|
| 162 |
describes how arguments can be specified for the calls to these
|
| 163 |
constructors. — *end note*]
|
| 164 |
|
| 165 |
#### Copy/move constructors <a id="class.copy.ctor">[[class.copy.ctor]]</a>
|
|
@@ -287,11 +287,11 @@ form
|
|
| 287 |
X::X(const X&)
|
| 288 |
```
|
| 289 |
|
| 290 |
if each potentially constructed subobject of a class type `M` (or array
|
| 291 |
thereof) has a copy constructor whose first parameter is of type `const`
|
| 292 |
-
`M&` or `const` `volatile` `M&`.[^
|
| 293 |
|
| 294 |
Otherwise, the implicitly-declared copy constructor will have the form
|
| 295 |
|
| 296 |
``` cpp
|
| 297 |
X::X(X&)
|
|
@@ -319,29 +319,28 @@ X::X(X&&)
|
|
| 319 |
|
| 320 |
An implicitly-declared copy/move constructor is an inline public member
|
| 321 |
of its class. A defaulted copy/move constructor for a class `X` is
|
| 322 |
defined as deleted [[dcl.fct.def.delete]] if `X` has:
|
| 323 |
|
| 324 |
-
- a potentially constructed subobject of type `M` (or
|
| 325 |
-
|
| 326 |
[[over.match]], as applied to find `M`’s corresponding constructor,
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
is deleted or inaccessible from the defaulted constructor, or,
|
| 333 |
- for the copy constructor, a non-static data member of rvalue reference
|
| 334 |
type.
|
| 335 |
|
| 336 |
[*Note 4*: A defaulted move constructor that is defined as deleted is
|
| 337 |
ignored by overload resolution [[over.match]], [[over.over]]. Such a
|
| 338 |
constructor would otherwise interfere with initialization from an rvalue
|
| 339 |
which can use the copy constructor instead. — *end note*]
|
| 340 |
|
| 341 |
A copy/move constructor for class `X` is trivial if it is not
|
| 342 |
-
user-provided and if
|
| 343 |
|
| 344 |
- class `X` has no virtual functions [[class.virtual]] and no virtual
|
| 345 |
base classes [[class.mi]], and
|
| 346 |
- the constructor selected to copy/move each direct base class subobject
|
| 347 |
is trivial, and
|
|
@@ -353,13 +352,12 @@ otherwise the copy/move constructor is *non-trivial*.
|
|
| 353 |
|
| 354 |
[*Note 5*: The copy/move constructor is implicitly defined even if the
|
| 355 |
implementation elided its odr-use
|
| 356 |
[[term.odr.use]], [[class.temporary]]. — *end note*]
|
| 357 |
|
| 358 |
-
|
| 359 |
-
constexpr
|
| 360 |
-
is `constexpr`.
|
| 361 |
|
| 362 |
Before the defaulted copy/move constructor for a class is implicitly
|
| 363 |
defined, all non-user-provided copy/move constructors for its
|
| 364 |
potentially constructed subobjects are implicitly defined.
|
| 365 |
|
|
@@ -368,11 +366,11 @@ exception specification [[except.spec]]. — *end note*]
|
|
| 368 |
|
| 369 |
The implicitly-defined copy/move constructor for a non-union class `X`
|
| 370 |
performs a memberwise copy/move of its bases and members.
|
| 371 |
|
| 372 |
[*Note 7*: Default member initializers of non-static data members are
|
| 373 |
-
ignored.
|
| 374 |
|
| 375 |
The order of initialization is the same as the order of initialization
|
| 376 |
of bases and members in a user-defined constructor (see
|
| 377 |
[[class.base.init]]). Let `x` be either the parameter of the constructor
|
| 378 |
or, for the move constructor, an xvalue referring to the parameter. Each
|
|
|
|
| 56 |
— *end example*]
|
| 57 |
|
| 58 |
[*Note 2*: For initialization of objects of class type see
|
| 59 |
[[class.init]]. — *end note*]
|
| 60 |
|
|
|
|
|
|
|
| 61 |
[*Note 3*: [[class.temporary]] describes the lifetime of temporary
|
| 62 |
objects. — *end note*]
|
| 63 |
|
| 64 |
[*Note 4*: Explicit constructor calls do not yield lvalues, see
|
| 65 |
[[basic.lval]]. — *end note*]
|
|
|
|
| 85 |
#### Default constructors <a id="class.default.ctor">[[class.default.ctor]]</a>
|
| 86 |
|
| 87 |
A *default constructor* for a class `X` is a constructor of class `X`
|
| 88 |
for which each parameter that is not a function parameter pack has a
|
| 89 |
default argument (including the case of a constructor with no
|
| 90 |
+
parameters). If there is no user-declared constructor or constructor
|
| 91 |
+
template for class `X`, a non-explicit constructor having no parameters
|
| 92 |
+
is implicitly declared as defaulted [[dcl.fct.def]]. An
|
| 93 |
+
implicitly-declared default constructor is an inline public member of
|
| 94 |
+
its class.
|
| 95 |
|
| 96 |
+
A defaulted default constructor for class `X` is defined as deleted if
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
- any non-static data member with no default member initializer
|
| 99 |
[[class.mem]] is of reference type,
|
| 100 |
+
- `X` is a non-union class and any non-variant non-static data member of
|
| 101 |
+
const-qualified type (or possibly multidimensional array thereof) with
|
| 102 |
+
no *brace-or-equal-initializer* is not const-default-constructible
|
| 103 |
+
[[dcl.init]],
|
| 104 |
+
- any non-variant potentially constructed subobject, except for a
|
| 105 |
+
non-static data member with a *brace-or-equal-initializer*, has class
|
| 106 |
+
type `M` (or possibly multidimensional array thereof) and overload
|
|
|
|
|
|
|
|
|
|
| 107 |
resolution [[over.match]] as applied to find `M`’s corresponding
|
| 108 |
+
constructor does not result in a usable candidate
|
| 109 |
+
[[over.match.general]], or
|
| 110 |
+
- any potentially constructed subobject S has class type `M` (or
|
| 111 |
+
possibly multidimensional array thereof), `M` has a destructor that is
|
| 112 |
+
deleted or inaccessible from the defaulted default constructor, and
|
| 113 |
+
either S is non-variant or S has a default member initializer.
|
| 114 |
|
| 115 |
+
A default constructor for a class `X` is *trivial* if it is not
|
| 116 |
+
user-provided and if
|
| 117 |
|
| 118 |
+
- `X` has no virtual functions [[class.virtual]] and no virtual base
|
| 119 |
+
classes [[class.mi]], and
|
| 120 |
+
- no non-static data member of `X` has a default member initializer
|
| 121 |
+
[[class.mem]], and
|
| 122 |
+
- all the direct base classes of `X` have trivial default constructors,
|
| 123 |
+
and
|
| 124 |
+
- either `X` is a union or for all the non-variant non-static data
|
| 125 |
+
members of `X` that are of class type (or array thereof), each such
|
| 126 |
+
class has a trivial default constructor.
|
| 127 |
|
| 128 |
Otherwise, the default constructor is *non-trivial*.
|
| 129 |
|
| 130 |
+
If a default constructor of a union-like class `X` is trivial, then for
|
| 131 |
+
each union `U` that is either `X` or an anonymous union member of `X`,
|
| 132 |
+
if the first variant member, if any, of `U` has implicit-lifetime type
|
| 133 |
+
[[basic.types.general]], the default constructor of `X` begins the
|
| 134 |
+
lifetime of that member if it is not the active member of its union.
|
| 135 |
+
|
| 136 |
+
[*Note 1*: It is already the active member if `U` was
|
| 137 |
+
value-initialized. — *end note*]
|
| 138 |
+
|
| 139 |
+
Otherwise, an implicitly-defined [[dcl.fct.def.default]] default
|
| 140 |
+
constructor performs the set of initializations of the class that would
|
| 141 |
+
be performed by a user-written default constructor for that class with
|
| 142 |
+
no *ctor-initializer* [[class.base.init]] and an empty
|
| 143 |
*compound-statement*. If that user-written default constructor would be
|
| 144 |
+
ill-formed, the program is ill-formed. The implicitly-defined default
|
| 145 |
+
constructor is `constexpr`. Before the defaulted default constructor for
|
| 146 |
+
a class is implicitly defined, all the non-user-provided default
|
| 147 |
+
constructors for its base classes and its non-static data members are
|
| 148 |
+
implicitly defined.
|
|
|
|
| 149 |
|
| 150 |
+
[*Note 2*: An implicitly-declared default constructor has an exception
|
| 151 |
specification [[except.spec]]. An explicitly-defaulted definition might
|
| 152 |
have an implicit exception specification, see
|
| 153 |
[[dcl.fct.def]]. — *end note*]
|
| 154 |
|
| 155 |
+
[*Note 3*: A default constructor is implicitly invoked to initialize a
|
| 156 |
class object when no initializer is specified [[dcl.init.general]]. Such
|
| 157 |
+
a default constructor needs to be accessible
|
| 158 |
[[class.access]]. — *end note*]
|
| 159 |
|
| 160 |
+
[*Note 4*: [[class.base.init]] describes the order in which
|
| 161 |
constructors for base classes and non-static data members are called and
|
| 162 |
describes how arguments can be specified for the calls to these
|
| 163 |
constructors. — *end note*]
|
| 164 |
|
| 165 |
#### Copy/move constructors <a id="class.copy.ctor">[[class.copy.ctor]]</a>
|
|
|
|
| 287 |
X::X(const X&)
|
| 288 |
```
|
| 289 |
|
| 290 |
if each potentially constructed subobject of a class type `M` (or array
|
| 291 |
thereof) has a copy constructor whose first parameter is of type `const`
|
| 292 |
+
`M&` or `const` `volatile` `M&`.[^2]
|
| 293 |
|
| 294 |
Otherwise, the implicitly-declared copy constructor will have the form
|
| 295 |
|
| 296 |
``` cpp
|
| 297 |
X::X(X&)
|
|
|
|
| 319 |
|
| 320 |
An implicitly-declared copy/move constructor is an inline public member
|
| 321 |
of its class. A defaulted copy/move constructor for a class `X` is
|
| 322 |
defined as deleted [[dcl.fct.def.delete]] if `X` has:
|
| 323 |
|
| 324 |
+
- a potentially constructed subobject of type `M` (or possibly
|
| 325 |
+
multidimensional array thereof) for which overload resolution
|
| 326 |
[[over.match]], as applied to find `M`’s corresponding constructor,
|
| 327 |
+
either does not result in a usable candidate [[over.match.general]]
|
| 328 |
+
or, in the case of a variant member, selects a non-trivial function,
|
| 329 |
+
- any potentially constructed subobject of class type `M` (or possibly
|
| 330 |
+
multidimensional array thereof) where `M` has a destructor that is
|
| 331 |
+
deleted or inaccessible from the defaulted constructor, or,
|
|
|
|
| 332 |
- for the copy constructor, a non-static data member of rvalue reference
|
| 333 |
type.
|
| 334 |
|
| 335 |
[*Note 4*: A defaulted move constructor that is defined as deleted is
|
| 336 |
ignored by overload resolution [[over.match]], [[over.over]]. Such a
|
| 337 |
constructor would otherwise interfere with initialization from an rvalue
|
| 338 |
which can use the copy constructor instead. — *end note*]
|
| 339 |
|
| 340 |
A copy/move constructor for class `X` is trivial if it is not
|
| 341 |
+
user-provided and if
|
| 342 |
|
| 343 |
- class `X` has no virtual functions [[class.virtual]] and no virtual
|
| 344 |
base classes [[class.mi]], and
|
| 345 |
- the constructor selected to copy/move each direct base class subobject
|
| 346 |
is trivial, and
|
|
|
|
| 352 |
|
| 353 |
[*Note 5*: The copy/move constructor is implicitly defined even if the
|
| 354 |
implementation elided its odr-use
|
| 355 |
[[term.odr.use]], [[class.temporary]]. — *end note*]
|
| 356 |
|
| 357 |
+
The implicitly-defined [[dcl.fct.def.default]] constructor is
|
| 358 |
+
`constexpr`.
|
|
|
|
| 359 |
|
| 360 |
Before the defaulted copy/move constructor for a class is implicitly
|
| 361 |
defined, all non-user-provided copy/move constructors for its
|
| 362 |
potentially constructed subobjects are implicitly defined.
|
| 363 |
|
|
|
|
| 366 |
|
| 367 |
The implicitly-defined copy/move constructor for a non-union class `X`
|
| 368 |
performs a memberwise copy/move of its bases and members.
|
| 369 |
|
| 370 |
[*Note 7*: Default member initializers of non-static data members are
|
| 371 |
+
ignored. — *end note*]
|
| 372 |
|
| 373 |
The order of initialization is the same as the order of initialization
|
| 374 |
of bases and members in a user-defined constructor (see
|
| 375 |
[[class.base.init]]). Let `x` be either the parameter of the constructor
|
| 376 |
or, for the move constructor, an xvalue referring to the parameter. Each
|