tmp/tmph0_vuxb6/{from.md → to.md}
RENAMED
|
@@ -15,52 +15,58 @@ explicitly defaulted shall
|
|
| 15 |
copy assignment operator, the parameter type may be “reference to
|
| 16 |
non-const `T`”, where `T` is the name of the member function’s class)
|
| 17 |
as if it had been implicitly declared, and
|
| 18 |
- not have default arguments.
|
| 19 |
|
| 20 |
-
An explicitly-defaulted function
|
| 21 |
-
would have been implicitly declared as
|
| 22 |
-
explicitly defaulted on its first
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
as if it had been implicitly declared ([[except.spec]]).
|
| 28 |
-
|
| 29 |
-
If a function that is explicitly defaulted has an explicit
|
| 30 |
-
*exception-specification* that is not compatible ([[except.spec]]) with
|
| 31 |
-
the *exception-specification* on the implicit declaration, then
|
| 32 |
|
| 33 |
- if the function is explicitly defaulted on its first declaration, it
|
| 34 |
is defined as deleted;
|
| 35 |
- otherwise, the program is ill-formed.
|
| 36 |
|
|
|
|
|
|
|
| 37 |
``` cpp
|
| 38 |
struct S {
|
| 39 |
constexpr S() = default; // ill-formed: implicit S() is not constexpr
|
| 40 |
S(int a = 0) = default; // ill-formed: default argument
|
| 41 |
void operator=(const S&) = default; // ill-formed: non-matching return type
|
| 42 |
-
~S()
|
| 43 |
private:
|
| 44 |
int i;
|
| 45 |
S(S&); // OK: private copy constructor
|
| 46 |
};
|
| 47 |
S::S(S&) = default; // OK: defines copy constructor
|
| 48 |
```
|
| 49 |
|
|
|
|
|
|
|
| 50 |
Explicitly-defaulted functions and implicitly-declared functions are
|
| 51 |
collectively called *defaulted* functions, and the implementation shall
|
| 52 |
provide implicit definitions for them ([[class.ctor]] [[class.dtor]],
|
| 53 |
[[class.copy]]), which might mean defining them as deleted. A function
|
| 54 |
is *user-provided* if it is user-declared and not explicitly defaulted
|
| 55 |
or deleted on its first declaration. A user-provided
|
| 56 |
explicitly-defaulted function (i.e., explicitly defaulted after its
|
| 57 |
first declaration) is defined at the point where it is explicitly
|
| 58 |
defaulted; if such a function is implicitly defined as deleted, the
|
| 59 |
-
program is ill-formed.
|
|
|
|
|
|
|
| 60 |
declaration can provide efficient execution and concise definition while
|
| 61 |
-
enabling a stable binary interface to an evolving code
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
``` cpp
|
| 64 |
struct trivial {
|
| 65 |
trivial() = default;
|
| 66 |
trivial(const trivial&) = default;
|
|
@@ -74,5 +80,7 @@ struct nontrivial1 {
|
|
| 74 |
nontrivial1();
|
| 75 |
};
|
| 76 |
nontrivial1::nontrivial1() = default; // not first declaration
|
| 77 |
```
|
| 78 |
|
|
|
|
|
|
|
|
|
| 15 |
copy assignment operator, the parameter type may be “reference to
|
| 16 |
non-const `T`”, where `T` is the name of the member function’s class)
|
| 17 |
as if it had been implicitly declared, and
|
| 18 |
- not have default arguments.
|
| 19 |
|
| 20 |
+
An explicitly-defaulted function that is not defined as deleted may be
|
| 21 |
+
declared `constexpr` only if it would have been implicitly declared as
|
| 22 |
+
`constexpr`. If a function is explicitly defaulted on its first
|
| 23 |
+
declaration, it is implicitly considered to be `constexpr` if the
|
| 24 |
+
implicit declaration would be.
|
| 25 |
|
| 26 |
+
If a function that is explicitly defaulted is declared with a
|
| 27 |
+
*noexcept-specifier* that does not produce the same exception
|
| 28 |
+
specification as the implicit declaration ([[except.spec]]), then
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
- if the function is explicitly defaulted on its first declaration, it
|
| 31 |
is defined as deleted;
|
| 32 |
- otherwise, the program is ill-formed.
|
| 33 |
|
| 34 |
+
[*Example 1*:
|
| 35 |
+
|
| 36 |
``` cpp
|
| 37 |
struct S {
|
| 38 |
constexpr S() = default; // ill-formed: implicit S() is not constexpr
|
| 39 |
S(int a = 0) = default; // ill-formed: default argument
|
| 40 |
void operator=(const S&) = default; // ill-formed: non-matching return type
|
| 41 |
+
~S() noexcept(false) = default; // deleted: exception specification does not match
|
| 42 |
private:
|
| 43 |
int i;
|
| 44 |
S(S&); // OK: private copy constructor
|
| 45 |
};
|
| 46 |
S::S(S&) = default; // OK: defines copy constructor
|
| 47 |
```
|
| 48 |
|
| 49 |
+
— *end example*]
|
| 50 |
+
|
| 51 |
Explicitly-defaulted functions and implicitly-declared functions are
|
| 52 |
collectively called *defaulted* functions, and the implementation shall
|
| 53 |
provide implicit definitions for them ([[class.ctor]] [[class.dtor]],
|
| 54 |
[[class.copy]]), which might mean defining them as deleted. A function
|
| 55 |
is *user-provided* if it is user-declared and not explicitly defaulted
|
| 56 |
or deleted on its first declaration. A user-provided
|
| 57 |
explicitly-defaulted function (i.e., explicitly defaulted after its
|
| 58 |
first declaration) is defined at the point where it is explicitly
|
| 59 |
defaulted; if such a function is implicitly defined as deleted, the
|
| 60 |
+
program is ill-formed.
|
| 61 |
+
|
| 62 |
+
[*Note 1*: Declaring a function as defaulted after its first
|
| 63 |
declaration can provide efficient execution and concise definition while
|
| 64 |
+
enabling a stable binary interface to an evolving code
|
| 65 |
+
base. — *end note*]
|
| 66 |
+
|
| 67 |
+
[*Example 2*:
|
| 68 |
|
| 69 |
``` cpp
|
| 70 |
struct trivial {
|
| 71 |
trivial() = default;
|
| 72 |
trivial(const trivial&) = default;
|
|
|
|
| 80 |
nontrivial1();
|
| 81 |
};
|
| 82 |
nontrivial1::nontrivial1() = default; // not first declaration
|
| 83 |
```
|
| 84 |
|
| 85 |
+
— *end example*]
|
| 86 |
+
|