From Jason Turner

[dcl.fct.def.default]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpu0mc5gzy/{from.md → to.md} +40 -32
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
- The type `T`₁ of an explicitly defaulted special member function `F` is
12
- allowed to differ from the type `T`₂ it would have had if it were
13
- implicitly declared, as follows:
14
 
15
- - `T`₁ and `T`₂ may have differing *ref-qualifier*s;
16
- - `T` and `T`₂ may have differing exception specifications; and
17
- - if `T` has a parameter of type `const C&`, the corresponding
18
- parameter of `T` may be of type `C&`.
 
 
 
 
 
19
 
20
- If `T`₁ differs from `T`₂ in any other way, then:
 
21
 
22
- - if `F` is an assignment operator, and the return type of `T`₁ differs
23
- from the return type of `T`₂ or `T`₁’s parameter type is not a
24
- reference, the program is ill-formed;
25
- - otherwise, if `F` is explicitly defaulted on its first declaration, it
26
- is defined as deleted;
27
  - otherwise, the program is ill-formed.
28
 
29
- An explicitly-defaulted function that is not defined as deleted may be
30
- declared `constexpr` or `consteval` only if it is constexpr-compatible (
31
- [[special]], [[class.compare.default]]). A function explicitly defaulted
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: private copy constructor
46
  };
47
- S::S(S&) = default; // OK: defines copy constructor
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 ([[class.ctor]], [[class.dtor]],
67
- [[class.copy.ctor]], [[class.copy.assign]]), which might mean defining
68
- them as deleted. A defaulted prospective destructor [[class.dtor]] that
69
- is not a destructor is defined as deleted. A defaulted special member
70
- function that is neither a prospective destructor nor an eligible
71
- special member function [[special]] is defined as deleted. A function is
72
- *user-provided* if it is user-declared and not explicitly defaulted or
73
- deleted on its first declaration. A user-provided explicitly-defaulted
74
- function (i.e., explicitly defaulted after its first declaration) is
75
- defined at the point where it is explicitly defaulted; if such a
76
- function is implicitly defined as deleted, the program is ill-formed.
 
 
 
 
 
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*]