tmp/tmpaz9sxp4v/{from.md → to.md}
RENAMED
|
@@ -44,11 +44,11 @@ Y e = d; // calls Y(const Y&)
|
|
| 44 |
|
| 45 |
— *end example*]
|
| 46 |
|
| 47 |
[*Note 1*:
|
| 48 |
|
| 49 |
-
All forms of copy/move constructor
|
| 50 |
|
| 51 |
[*Example 3*:
|
| 52 |
|
| 53 |
``` cpp
|
| 54 |
struct X {
|
|
@@ -110,25 +110,26 @@ void h() {
|
|
| 110 |
|
| 111 |
If the class definition does not explicitly declare a copy constructor,
|
| 112 |
a non-explicit one is declared *implicitly*. If the class definition
|
| 113 |
declares a move constructor or move assignment operator, the implicitly
|
| 114 |
declared copy constructor is defined as deleted; otherwise, it is
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
|
| 119 |
The implicitly-declared copy constructor for a class `X` will have the
|
| 120 |
form
|
| 121 |
|
| 122 |
``` cpp
|
| 123 |
X::X(const X&)
|
| 124 |
```
|
| 125 |
|
| 126 |
if each potentially constructed subobject of a class type `M` (or array
|
| 127 |
thereof) has a copy constructor whose first parameter is of type `const`
|
| 128 |
-
`M&` or `const` `volatile` `M&`.[^3]
|
| 129 |
-
|
|
|
|
| 130 |
|
| 131 |
``` cpp
|
| 132 |
X::X(X&)
|
| 133 |
```
|
| 134 |
|
|
@@ -141,11 +142,11 @@ if and only if
|
|
| 141 |
- `X` does not have a user-declared move assignment operator, and
|
| 142 |
- `X` does not have a user-declared destructor.
|
| 143 |
|
| 144 |
[*Note 3*: When the move constructor is not implicitly declared or
|
| 145 |
explicitly supplied, expressions that otherwise would have invoked the
|
| 146 |
-
move constructor
|
| 147 |
|
| 148 |
The implicitly-declared move constructor for class `X` will have the
|
| 149 |
form
|
| 150 |
|
| 151 |
``` cpp
|
|
@@ -154,24 +155,24 @@ X::X(X&&)
|
|
| 154 |
|
| 155 |
An implicitly-declared copy/move constructor is an inline public member
|
| 156 |
of its class. A defaulted copy/move constructor for a class `X` is
|
| 157 |
defined as deleted [[dcl.fct.def.delete]] if `X` has:
|
| 158 |
|
| 159 |
-
- a potentially constructed subobject type `M` (or array thereof)
|
| 160 |
-
cannot be copied/moved because overload resolution
|
| 161 |
-
applied to find `M`’s corresponding constructor,
|
| 162 |
-
ambiguity or a function that is deleted or inaccessible
|
| 163 |
-
defaulted constructor,
|
| 164 |
- a variant member whose corresponding constructor as selected by
|
| 165 |
overload resolution is non-trivial,
|
| 166 |
- any potentially constructed subobject of a type with a destructor that
|
| 167 |
is deleted or inaccessible from the defaulted constructor, or,
|
| 168 |
- for the copy constructor, a non-static data member of rvalue reference
|
| 169 |
type.
|
| 170 |
|
| 171 |
[*Note 4*: A defaulted move constructor that is defined as deleted is
|
| 172 |
-
ignored by overload resolution
|
| 173 |
constructor would otherwise interfere with initialization from an rvalue
|
| 174 |
which can use the copy constructor instead. — *end note*]
|
| 175 |
|
| 176 |
A copy/move constructor for class `X` is trivial if it is not
|
| 177 |
user-provided and if:
|
|
@@ -184,22 +185,17 @@ user-provided and if:
|
|
| 184 |
thereof), the constructor selected to copy/move that member is
|
| 185 |
trivial;
|
| 186 |
|
| 187 |
otherwise the copy/move constructor is *non-trivial*.
|
| 188 |
|
| 189 |
-
A copy/move constructor that is defaulted and not defined as deleted is
|
| 190 |
-
*implicitly defined* when it is odr-used [[basic.def.odr]], when it is
|
| 191 |
-
needed for constant evaluation [[expr.const]], or when it is explicitly
|
| 192 |
-
defaulted after its first declaration.
|
| 193 |
-
|
| 194 |
[*Note 5*: The copy/move constructor is implicitly defined even if the
|
| 195 |
-
implementation elided its odr-use
|
| 196 |
-
[[class.temporary]]
|
| 197 |
|
| 198 |
-
If
|
| 199 |
-
|
| 200 |
-
|
| 201 |
|
| 202 |
Before the defaulted copy/move constructor for a class is implicitly
|
| 203 |
defined, all non-user-provided copy/move constructors for its
|
| 204 |
potentially constructed subobjects are implicitly defined.
|
| 205 |
|
|
@@ -228,11 +224,11 @@ to its type:
|
|
| 228 |
|
| 229 |
Virtual base class subobjects shall be initialized only once by the
|
| 230 |
implicitly-defined copy/move constructor (see [[class.base.init]]).
|
| 231 |
|
| 232 |
The implicitly-defined copy/move constructor for a union `X` copies the
|
| 233 |
-
object representation [[
|
| 234 |
-
within [[intro.object]] the object that is the source of
|
| 235 |
-
corresponding object o nested within the destination is
|
| 236 |
-
the object is a subobject) or created (otherwise), and
|
| 237 |
-
begins before the copy is performed.
|
| 238 |
|
|
|
|
| 44 |
|
| 45 |
— *end example*]
|
| 46 |
|
| 47 |
[*Note 1*:
|
| 48 |
|
| 49 |
+
All forms of copy/move constructor can be declared for a class.
|
| 50 |
|
| 51 |
[*Example 3*:
|
| 52 |
|
| 53 |
``` cpp
|
| 54 |
struct X {
|
|
|
|
| 110 |
|
| 111 |
If the class definition does not explicitly declare a copy constructor,
|
| 112 |
a non-explicit one is declared *implicitly*. If the class definition
|
| 113 |
declares a move constructor or move assignment operator, the implicitly
|
| 114 |
declared copy constructor is defined as deleted; otherwise, it is
|
| 115 |
+
defaulted [[dcl.fct.def]]. The latter case is deprecated if the class
|
| 116 |
+
has a user-declared copy assignment operator or a user-declared
|
| 117 |
+
destructor [[depr.impldec]].
|
| 118 |
|
| 119 |
The implicitly-declared copy constructor for a class `X` will have the
|
| 120 |
form
|
| 121 |
|
| 122 |
``` cpp
|
| 123 |
X::X(const X&)
|
| 124 |
```
|
| 125 |
|
| 126 |
if each potentially constructed subobject of a class type `M` (or array
|
| 127 |
thereof) has a copy constructor whose first parameter is of type `const`
|
| 128 |
+
`M&` or `const` `volatile` `M&`.[^3]
|
| 129 |
+
|
| 130 |
+
Otherwise, the implicitly-declared copy constructor will have the form
|
| 131 |
|
| 132 |
``` cpp
|
| 133 |
X::X(X&)
|
| 134 |
```
|
| 135 |
|
|
|
|
| 142 |
- `X` does not have a user-declared move assignment operator, and
|
| 143 |
- `X` does not have a user-declared destructor.
|
| 144 |
|
| 145 |
[*Note 3*: When the move constructor is not implicitly declared or
|
| 146 |
explicitly supplied, expressions that otherwise would have invoked the
|
| 147 |
+
move constructor might instead invoke a copy constructor. — *end note*]
|
| 148 |
|
| 149 |
The implicitly-declared move constructor for class `X` will have the
|
| 150 |
form
|
| 151 |
|
| 152 |
``` cpp
|
|
|
|
| 155 |
|
| 156 |
An implicitly-declared copy/move constructor is an inline public member
|
| 157 |
of its class. A defaulted copy/move constructor for a class `X` is
|
| 158 |
defined as deleted [[dcl.fct.def.delete]] if `X` has:
|
| 159 |
|
| 160 |
+
- a potentially constructed subobject of type `M` (or array thereof)
|
| 161 |
+
that cannot be copied/moved because overload resolution
|
| 162 |
+
[[over.match]], as applied to find `M`’s corresponding constructor,
|
| 163 |
+
results in an ambiguity or a function that is deleted or inaccessible
|
| 164 |
+
from the defaulted constructor,
|
| 165 |
- a variant member whose corresponding constructor as selected by
|
| 166 |
overload resolution is non-trivial,
|
| 167 |
- any potentially constructed subobject of a type with a destructor that
|
| 168 |
is deleted or inaccessible from the defaulted constructor, or,
|
| 169 |
- for the copy constructor, a non-static data member of rvalue reference
|
| 170 |
type.
|
| 171 |
|
| 172 |
[*Note 4*: A defaulted move constructor that is defined as deleted is
|
| 173 |
+
ignored by overload resolution [[over.match]], [[over.over]]. Such a
|
| 174 |
constructor would otherwise interfere with initialization from an rvalue
|
| 175 |
which can use the copy constructor instead. — *end note*]
|
| 176 |
|
| 177 |
A copy/move constructor for class `X` is trivial if it is not
|
| 178 |
user-provided and if:
|
|
|
|
| 185 |
thereof), the constructor selected to copy/move that member is
|
| 186 |
trivial;
|
| 187 |
|
| 188 |
otherwise the copy/move constructor is *non-trivial*.
|
| 189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
[*Note 5*: The copy/move constructor is implicitly defined even if the
|
| 191 |
+
implementation elided its odr-use
|
| 192 |
+
[[term.odr.use]], [[class.temporary]]. — *end note*]
|
| 193 |
|
| 194 |
+
If an implicitly-defined [[dcl.fct.def.default]] constructor would be
|
| 195 |
+
constexpr-suitable [[dcl.constexpr]], the implicitly-defined constructor
|
| 196 |
+
is `constexpr`.
|
| 197 |
|
| 198 |
Before the defaulted copy/move constructor for a class is implicitly
|
| 199 |
defined, all non-user-provided copy/move constructors for its
|
| 200 |
potentially constructed subobjects are implicitly defined.
|
| 201 |
|
|
|
|
| 224 |
|
| 225 |
Virtual base class subobjects shall be initialized only once by the
|
| 226 |
implicitly-defined copy/move constructor (see [[class.base.init]]).
|
| 227 |
|
| 228 |
The implicitly-defined copy/move constructor for a union `X` copies the
|
| 229 |
+
object representation [[term.object.representation]] of `X`. For each
|
| 230 |
+
object nested within [[intro.object]] the object that is the source of
|
| 231 |
+
the copy, a corresponding object o nested within the destination is
|
| 232 |
+
identified (if the object is a subobject) or created (otherwise), and
|
| 233 |
+
the lifetime of o begins before the copy is performed.
|
| 234 |
|