tmp/tmpu67t8_5k/{from.md → to.md}
RENAMED
|
@@ -14,14 +14,14 @@ then
|
|
| 14 |
|
| 15 |
- for some argument j, ICSʲ(`F₁`) is a better conversion sequence than
|
| 16 |
ICSʲ(`F₂`), or, if not that,
|
| 17 |
- the context is an initialization by user-defined conversion (see
|
| 18 |
[[dcl.init]], [[over.match.conv]], and [[over.match.ref]]) and the
|
| 19 |
-
standard conversion sequence from the
|
| 20 |
destination type (i.e., the type of the entity being initialized) is a
|
| 21 |
better conversion sequence than the standard conversion sequence from
|
| 22 |
-
the
|
| 23 |
\[*Example 1*:
|
| 24 |
``` cpp
|
| 25 |
struct A {
|
| 26 |
A();
|
| 27 |
operator int();
|
|
@@ -35,13 +35,13 @@ then
|
|
| 35 |
|
| 36 |
— *end example*]
|
| 37 |
or, if not that,
|
| 38 |
- the context is an initialization by conversion function for direct
|
| 39 |
reference binding [[over.match.ref]] of a reference to function type,
|
| 40 |
-
the return type of `
|
| 41 |
rvalue) as the reference being initialized, and the return type of
|
| 42 |
-
`
|
| 43 |
\[*Example 2*:
|
| 44 |
``` cpp
|
| 45 |
template <class T> struct A {
|
| 46 |
operator T&(); // #1
|
| 47 |
operator T&&(); // #2
|
|
@@ -52,25 +52,39 @@ then
|
|
| 52 |
Fn&& rf = a; // calls #2
|
| 53 |
```
|
| 54 |
|
| 55 |
— *end example*]
|
| 56 |
or, if not that,
|
| 57 |
-
- `
|
| 58 |
template specialization, or, if not that,
|
| 59 |
-
- `
|
| 60 |
-
template for `
|
| 61 |
according to the partial ordering rules described in
|
| 62 |
[[temp.func.order]], or, if not that,
|
| 63 |
-
- `
|
| 64 |
-
|
| 65 |
-
to the partial ordering of constraints described in
|
| 66 |
-
[[temp.constr.order]], or if not that,
|
| 67 |
-
- `F1` is a constructor for a class `D`, `F2` is a constructor for a
|
| 68 |
-
base class `B` of `D`, and for all arguments the corresponding
|
| 69 |
-
parameters of `F1` and `F2` have the same type
|
| 70 |
\[*Example 3*:
|
| 71 |
``` cpp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
struct A {
|
| 73 |
A(int = 0);
|
| 74 |
};
|
| 75 |
|
| 76 |
struct B: A {
|
|
@@ -83,48 +97,48 @@ then
|
|
| 83 |
}
|
| 84 |
```
|
| 85 |
|
| 86 |
— *end example*]
|
| 87 |
or, if not that,
|
| 88 |
-
- `
|
| 89 |
-
\[*Example
|
| 90 |
``` cpp
|
| 91 |
struct S {
|
| 92 |
friend auto operator<=>(const S&, const S&) = default; // #1
|
| 93 |
friend bool operator<(const S&, const S&); // #2
|
| 94 |
};
|
| 95 |
bool b = S() < S(); // calls #2
|
| 96 |
```
|
| 97 |
|
| 98 |
— *end example*]
|
| 99 |
or, if not that,
|
| 100 |
-
- `
|
| 101 |
-
candidate with reversed order of parameters and `
|
| 102 |
-
\[*Example
|
| 103 |
``` cpp
|
| 104 |
struct S {
|
| 105 |
friend std::weak_ordering operator<=>(const S&, int); // #1
|
| 106 |
friend std::weak_ordering operator<=>(int, const S&); // #2
|
| 107 |
};
|
| 108 |
bool b = 1 < S(); // calls #2
|
| 109 |
```
|
| 110 |
|
| 111 |
— *end example*]
|
| 112 |
-
or, if not that
|
| 113 |
-
- `
|
| 114 |
-
[[over.match.class.deduct]] for a class `D`, and `
|
| 115 |
-
from inheriting constructors from a base class of `D` while `
|
| 116 |
not, and for each explicit function argument, the corresponding
|
| 117 |
-
parameters of `
|
| 118 |
type, or, if not that,
|
| 119 |
-
- `
|
| 120 |
-
and `
|
| 121 |
-
- `
|
| 122 |
-
`
|
| 123 |
-
- `
|
| 124 |
generated from a constructor template.
|
| 125 |
-
\[*Example
|
| 126 |
``` cpp
|
| 127 |
template <class T> struct A {
|
| 128 |
using value_type = T;
|
| 129 |
A(value_type); // #1
|
| 130 |
A(const A&); // #2
|
|
@@ -152,11 +166,11 @@ then
|
|
| 152 |
|
| 153 |
If there is exactly one viable function that is a better function than
|
| 154 |
all other viable functions, then it is the one selected by overload
|
| 155 |
resolution; otherwise the call is ill-formed.[^7]
|
| 156 |
|
| 157 |
-
[*Example
|
| 158 |
|
| 159 |
``` cpp
|
| 160 |
void Fcn(const int*, short);
|
| 161 |
void Fcn(int*, int);
|
| 162 |
|
|
@@ -175,31 +189,9 @@ void f() {
|
|
| 175 |
}
|
| 176 |
```
|
| 177 |
|
| 178 |
— *end example*]
|
| 179 |
|
| 180 |
-
If the best viable function
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
viable, the program is ill-formed.
|
| 184 |
-
|
| 185 |
-
[*Example 8*:
|
| 186 |
-
|
| 187 |
-
``` cpp
|
| 188 |
-
namespace A {
|
| 189 |
-
extern "C" void f(int = 5);
|
| 190 |
-
}
|
| 191 |
-
namespace B {
|
| 192 |
-
extern "C" void f(int = 5);
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
using A::f;
|
| 196 |
-
using B::f;
|
| 197 |
-
|
| 198 |
-
void use() {
|
| 199 |
-
f(3); // OK, default argument was not used for viability
|
| 200 |
-
f(); // error: found default argument twice
|
| 201 |
-
}
|
| 202 |
-
```
|
| 203 |
-
|
| 204 |
-
— *end example*]
|
| 205 |
|
|
|
|
| 14 |
|
| 15 |
- for some argument j, ICSʲ(`F₁`) is a better conversion sequence than
|
| 16 |
ICSʲ(`F₂`), or, if not that,
|
| 17 |
- the context is an initialization by user-defined conversion (see
|
| 18 |
[[dcl.init]], [[over.match.conv]], and [[over.match.ref]]) and the
|
| 19 |
+
standard conversion sequence from the result of `F₁` to the
|
| 20 |
destination type (i.e., the type of the entity being initialized) is a
|
| 21 |
better conversion sequence than the standard conversion sequence from
|
| 22 |
+
the result of `F₂` to the destination type
|
| 23 |
\[*Example 1*:
|
| 24 |
``` cpp
|
| 25 |
struct A {
|
| 26 |
A();
|
| 27 |
operator int();
|
|
|
|
| 35 |
|
| 36 |
— *end example*]
|
| 37 |
or, if not that,
|
| 38 |
- the context is an initialization by conversion function for direct
|
| 39 |
reference binding [[over.match.ref]] of a reference to function type,
|
| 40 |
+
the return type of `F₁` is the same kind of reference (lvalue or
|
| 41 |
rvalue) as the reference being initialized, and the return type of
|
| 42 |
+
`F₂` is not
|
| 43 |
\[*Example 2*:
|
| 44 |
``` cpp
|
| 45 |
template <class T> struct A {
|
| 46 |
operator T&(); // #1
|
| 47 |
operator T&&(); // #2
|
|
|
|
| 52 |
Fn&& rf = a; // calls #2
|
| 53 |
```
|
| 54 |
|
| 55 |
— *end example*]
|
| 56 |
or, if not that,
|
| 57 |
+
- `F₁` is not a function template specialization and `F₂` is a function
|
| 58 |
template specialization, or, if not that,
|
| 59 |
+
- `F₁` and `F₂` are function template specializations, and the function
|
| 60 |
+
template for `F₁` is more specialized than the template for `F₂`
|
| 61 |
according to the partial ordering rules described in
|
| 62 |
[[temp.func.order]], or, if not that,
|
| 63 |
+
- `F₁` and `F₂` are non-template functions and `F₁` is more
|
| 64 |
+
partial-ordering-constrained than `F₂` [[temp.constr.order]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
\[*Example 3*:
|
| 66 |
``` cpp
|
| 67 |
+
template <typename T = int>
|
| 68 |
+
struct S {
|
| 69 |
+
constexpr void f(); // #1
|
| 70 |
+
constexpr void f(this S&) requires true; // #2
|
| 71 |
+
};
|
| 72 |
+
|
| 73 |
+
void test() {
|
| 74 |
+
S<> s;
|
| 75 |
+
s.f(); // calls #2
|
| 76 |
+
}
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
— *end example*]
|
| 80 |
+
or, if not that,
|
| 81 |
+
- `F₁` is a constructor for a class `D`, `F₂` is a constructor for a
|
| 82 |
+
base class `B` of `D`, and for all arguments the corresponding
|
| 83 |
+
parameters of `F₁` and `F₂` have the same type
|
| 84 |
+
\[*Example 4*:
|
| 85 |
+
``` cpp
|
| 86 |
struct A {
|
| 87 |
A(int = 0);
|
| 88 |
};
|
| 89 |
|
| 90 |
struct B: A {
|
|
|
|
| 97 |
}
|
| 98 |
```
|
| 99 |
|
| 100 |
— *end example*]
|
| 101 |
or, if not that,
|
| 102 |
+
- `F₂` is a rewritten candidate [[over.match.oper]] and `F₁` is not
|
| 103 |
+
\[*Example 5*:
|
| 104 |
``` cpp
|
| 105 |
struct S {
|
| 106 |
friend auto operator<=>(const S&, const S&) = default; // #1
|
| 107 |
friend bool operator<(const S&, const S&); // #2
|
| 108 |
};
|
| 109 |
bool b = S() < S(); // calls #2
|
| 110 |
```
|
| 111 |
|
| 112 |
— *end example*]
|
| 113 |
or, if not that,
|
| 114 |
+
- `F₁` and `F₂` are rewritten candidates, and `F₂` is a synthesized
|
| 115 |
+
candidate with reversed order of parameters and `F₁` is not
|
| 116 |
+
\[*Example 6*:
|
| 117 |
``` cpp
|
| 118 |
struct S {
|
| 119 |
friend std::weak_ordering operator<=>(const S&, int); // #1
|
| 120 |
friend std::weak_ordering operator<=>(int, const S&); // #2
|
| 121 |
};
|
| 122 |
bool b = 1 < S(); // calls #2
|
| 123 |
```
|
| 124 |
|
| 125 |
— *end example*]
|
| 126 |
+
or, if not that,
|
| 127 |
+
- `F₁` and `F₂` are generated from class template argument deduction
|
| 128 |
+
[[over.match.class.deduct]] for a class `D`, and `F₂` is generated
|
| 129 |
+
from inheriting constructors from a base class of `D` while `F₁` is
|
| 130 |
not, and for each explicit function argument, the corresponding
|
| 131 |
+
parameters of `F₁` and `F₂` are either both ellipses or have the same
|
| 132 |
type, or, if not that,
|
| 133 |
+
- `F₁` is generated from a *deduction-guide* [[over.match.class.deduct]]
|
| 134 |
+
and `F₂` is not, or, if not that,
|
| 135 |
+
- `F₁` is the copy deduction candidate [[over.match.class.deduct]] and
|
| 136 |
+
`F₂` is not, or, if not that,
|
| 137 |
+
- `F₁` is generated from a non-template constructor and `F₂` is
|
| 138 |
generated from a constructor template.
|
| 139 |
+
\[*Example 7*:
|
| 140 |
``` cpp
|
| 141 |
template <class T> struct A {
|
| 142 |
using value_type = T;
|
| 143 |
A(value_type); // #1
|
| 144 |
A(const A&); // #2
|
|
|
|
| 166 |
|
| 167 |
If there is exactly one viable function that is a better function than
|
| 168 |
all other viable functions, then it is the one selected by overload
|
| 169 |
resolution; otherwise the call is ill-formed.[^7]
|
| 170 |
|
| 171 |
+
[*Example 8*:
|
| 172 |
|
| 173 |
``` cpp
|
| 174 |
void Fcn(const int*, short);
|
| 175 |
void Fcn(int*, int);
|
| 176 |
|
|
|
|
| 189 |
}
|
| 190 |
```
|
| 191 |
|
| 192 |
— *end example*]
|
| 193 |
|
| 194 |
+
[*Note 1*: If the best viable function was made viable by one or more
|
| 195 |
+
default arguments, additional requirements apply
|
| 196 |
+
[[over.match.viable]]. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|