tmp/tmpu0mc5gzy/{from.md → to.md}
RENAMED
|
@@ -6,47 +6,50 @@ explicitly defaulted shall
|
|
| 6 |
|
| 7 |
- be a special member function or a comparison operator function
|
| 8 |
[[over.binary]], and
|
| 9 |
- not have default arguments.
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
implicitly declared, as follows:
|
| 14 |
|
| 15 |
-
- `
|
| 16 |
-
- `
|
| 17 |
-
|
| 18 |
-
parameter of `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
If `
|
|
|
|
| 21 |
|
| 22 |
-
- if `F` is an assignment operator, and the return type of `
|
| 23 |
-
from the return type of `
|
| 24 |
-
reference, the program is ill-formed;
|
| 25 |
-
- otherwise, if `F` is explicitly defaulted on its first declaration,
|
| 26 |
-
is defined as deleted;
|
| 27 |
- otherwise, the program is ill-formed.
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
on its first declaration is implicitly inline [[dcl.inline]], and is
|
| 33 |
-
implicitly constexpr [[dcl.constexpr]] if it is constexpr-compatible.
|
| 34 |
|
| 35 |
[*Example 1*:
|
| 36 |
|
| 37 |
``` cpp
|
| 38 |
struct S {
|
| 39 |
-
constexpr S() = default; // error: implicit S() is not constexpr
|
| 40 |
S(int a = 0) = default; // error: default argument
|
| 41 |
void operator=(const S&) = default; // error: non-matching return type
|
| 42 |
~S() noexcept(false) = default; // OK, despite mismatched exception specification
|
| 43 |
private:
|
| 44 |
int i;
|
| 45 |
-
S(S&); // OK
|
| 46 |
};
|
| 47 |
-
S::S(S&) = default; // OK
|
| 48 |
|
| 49 |
struct T {
|
| 50 |
T();
|
| 51 |
T(T &&) noexcept(false);
|
| 52 |
};
|
|
@@ -61,21 +64,26 @@ U u2 = static_cast<U&&>(u1); // OK, calls std::terminate if T::T(T&&)
|
|
| 61 |
|
| 62 |
— *end example*]
|
| 63 |
|
| 64 |
Explicitly-defaulted functions and implicitly-declared functions are
|
| 65 |
collectively called *defaulted* functions, and the implementation shall
|
| 66 |
-
provide implicit definitions for them
|
| 67 |
-
[[class.copy.ctor]], [[class.copy.assign]]
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
function (i.e.,
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
[*Note 1*: Declaring a function as defaulted after its first
|
| 79 |
declaration can provide efficient execution and concise definition while
|
| 80 |
enabling a stable binary interface to an evolving code
|
| 81 |
base. — *end note*]
|
|
|
|
| 6 |
|
| 7 |
- be a special member function or a comparison operator function
|
| 8 |
[[over.binary]], and
|
| 9 |
- not have default arguments.
|
| 10 |
|
| 11 |
+
An explicitly defaulted special member function `F₁` is allowed to
|
| 12 |
+
differ from the corresponding special member function `F₂` that would
|
| 13 |
+
have been implicitly declared, as follows:
|
| 14 |
|
| 15 |
+
- `F₁` and `F₂` may have differing *ref-qualifier*s;
|
| 16 |
+
- if `F₂` has an implicit object parameter of type “reference to `C`”,
|
| 17 |
+
`F₁` may be an explicit object member function whose explicit object
|
| 18 |
+
parameter is of type “reference to `C`”, in which case the type of
|
| 19 |
+
`F₁` would differ from the type of `F₂` in that the type of `F₁` has
|
| 20 |
+
an additional parameter;
|
| 21 |
+
- `F₁` and `F₂` may have differing exception specifications; and
|
| 22 |
+
- if `F₂` has a non-object parameter of type `const C&`, the
|
| 23 |
+
corresponding non-object parameter of `F₁` may be of type `C&`.
|
| 24 |
|
| 25 |
+
If the type of `F₁` differs from the type of `F₂` in a way other than as
|
| 26 |
+
allowed by the preceding rules, then:
|
| 27 |
|
| 28 |
+
- if `F₁` is an assignment operator, and the return type of `F₁` differs
|
| 29 |
+
from the return type of `F₂` or `F₁`’s non-object parameter type is
|
| 30 |
+
not a reference, the program is ill-formed;
|
| 31 |
+
- otherwise, if `F₁` is explicitly defaulted on its first declaration,
|
| 32 |
+
it is defined as deleted;
|
| 33 |
- otherwise, the program is ill-formed.
|
| 34 |
|
| 35 |
+
A function explicitly defaulted on its first declaration is implicitly
|
| 36 |
+
inline [[dcl.inline]], and is implicitly constexpr [[dcl.constexpr]] if
|
| 37 |
+
it is constexpr-suitable.
|
|
|
|
|
|
|
| 38 |
|
| 39 |
[*Example 1*:
|
| 40 |
|
| 41 |
``` cpp
|
| 42 |
struct S {
|
|
|
|
| 43 |
S(int a = 0) = default; // error: default argument
|
| 44 |
void operator=(const S&) = default; // error: non-matching return type
|
| 45 |
~S() noexcept(false) = default; // OK, despite mismatched exception specification
|
| 46 |
private:
|
| 47 |
int i;
|
| 48 |
+
S(S&); // OK, private copy constructor
|
| 49 |
};
|
| 50 |
+
S::S(S&) = default; // OK, defines copy constructor
|
| 51 |
|
| 52 |
struct T {
|
| 53 |
T();
|
| 54 |
T(T &&) noexcept(false);
|
| 55 |
};
|
|
|
|
| 64 |
|
| 65 |
— *end example*]
|
| 66 |
|
| 67 |
Explicitly-defaulted functions and implicitly-declared functions are
|
| 68 |
collectively called *defaulted* functions, and the implementation shall
|
| 69 |
+
provide implicit definitions for them
|
| 70 |
+
[[class.ctor]], [[class.dtor]], [[class.copy.ctor]], [[class.copy.assign]]
|
| 71 |
+
as described below, including possibly defining them as deleted. A
|
| 72 |
+
defaulted prospective destructor [[class.dtor]] that is not a destructor
|
| 73 |
+
is defined as deleted. A defaulted special member function that is
|
| 74 |
+
neither a prospective destructor nor an eligible special member function
|
| 75 |
+
[[special]] is defined as deleted. A function is *user-provided* if it
|
| 76 |
+
is user-declared and not explicitly defaulted or deleted on its first
|
| 77 |
+
declaration. A user-provided explicitly-defaulted function (i.e.,
|
| 78 |
+
explicitly defaulted after its first declaration) is implicitly defined
|
| 79 |
+
at the point where it is explicitly defaulted; if such a function is
|
| 80 |
+
implicitly defined as deleted, the program is ill-formed. A
|
| 81 |
+
non-user-provided defaulted function (i.e., implicitly declared or
|
| 82 |
+
explicitly defaulted in the class) that is not defined as deleted is
|
| 83 |
+
implicitly defined when it is odr-used [[basic.def.odr]] or needed for
|
| 84 |
+
constant evaluation [[expr.const]].
|
| 85 |
|
| 86 |
[*Note 1*: Declaring a function as defaulted after its first
|
| 87 |
declaration can provide efficient execution and concise definition while
|
| 88 |
enabling a stable binary interface to an evolving code
|
| 89 |
base. — *end note*]
|