tmp/tmpvzqbon8r/{from.md → to.md}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
### Explicitly-defaulted functions <a id="dcl.fct.def.default">[[dcl.fct.def.default]]</a>
|
| 2 |
|
| 3 |
A function definition of the form:
|
| 4 |
|
| 5 |
``` bnf
|
| 6 |
-
attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ declarator ' = default ;'
|
| 7 |
```
|
| 8 |
|
| 9 |
is called an *explicitly-defaulted* definition. A function that is
|
| 10 |
explicitly defaulted shall
|
| 11 |
|
|
@@ -16,50 +16,51 @@ explicitly defaulted shall
|
|
| 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 may be declared `constexpr` only if it
|
| 21 |
-
would have been implicitly declared as `constexpr`
|
| 22 |
-
|
| 23 |
-
[[except.spec]]) with the *exception-specification* on the implicit
|
| 24 |
-
declaration. If a function is explicitly defaulted on its first
|
| 25 |
-
declaration,
|
| 26 |
|
| 27 |
- it is implicitly considered to be `constexpr` if the implicit
|
| 28 |
-
declaration would be,
|
| 29 |
- it is implicitly considered to have the same *exception-specification*
|
| 30 |
-
as if it had been implicitly declared ([[except.spec]])
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
``` cpp
|
| 36 |
struct S {
|
| 37 |
constexpr S() = default; // ill-formed: implicit S() is not constexpr
|
| 38 |
S(int a = 0) = default; // ill-formed: default argument
|
| 39 |
void operator=(const S&) = default; // ill-formed: non-matching return type
|
| 40 |
-
~S() throw(int) = default; //
|
| 41 |
private:
|
| 42 |
int i;
|
| 43 |
S(S&); // OK: private copy constructor
|
| 44 |
};
|
| 45 |
S::S(S&) = default; // OK: defines copy constructor
|
| 46 |
```
|
| 47 |
|
| 48 |
Explicitly-defaulted functions and implicitly-declared functions are
|
| 49 |
collectively called *defaulted* functions, and the implementation shall
|
| 50 |
provide implicit definitions for them ([[class.ctor]] [[class.dtor]],
|
| 51 |
-
[[class.copy]]), which might mean defining them as deleted. A
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
base.
|
| 61 |
|
| 62 |
``` cpp
|
| 63 |
struct trivial {
|
| 64 |
trivial() = default;
|
| 65 |
trivial(const trivial&) = default;
|
|
|
|
| 1 |
### Explicitly-defaulted functions <a id="dcl.fct.def.default">[[dcl.fct.def.default]]</a>
|
| 2 |
|
| 3 |
A function definition of the form:
|
| 4 |
|
| 5 |
``` bnf
|
| 6 |
+
attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ declarator virt-specifier-seqₒₚₜ ' = default ;'
|
| 7 |
```
|
| 8 |
|
| 9 |
is called an *explicitly-defaulted* definition. A function that is
|
| 10 |
explicitly defaulted shall
|
| 11 |
|
|
|
|
| 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 may be declared `constexpr` only if it
|
| 21 |
+
would have been implicitly declared as `constexpr`. If a function is
|
| 22 |
+
explicitly defaulted on its first declaration,
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
- it is implicitly considered to be `constexpr` if the implicit
|
| 25 |
+
declaration would be, and,
|
| 26 |
- it is implicitly considered to have the same *exception-specification*
|
| 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() throw(int) = default; // deleted: exception specification does not match
|
| 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. Declaring a function as defaulted after its first
|
| 60 |
+
declaration can provide efficient execution and concise definition while
|
| 61 |
+
enabling a stable binary interface to an evolving code base.
|
|
|
|
| 62 |
|
| 63 |
``` cpp
|
| 64 |
struct trivial {
|
| 65 |
trivial() = default;
|
| 66 |
trivial(const trivial&) = default;
|