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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### General <a id="over.match.best.general">[[over.match.best.general]]</a>
|
| 2 |
+
|
| 3 |
+
Define ICSⁱ(`F`) as the implicit conversion sequence that converts the
|
| 4 |
+
iᵗʰ argument in the list to the type of the iᵗʰ parameter of viable
|
| 5 |
+
function `F`. [[over.best.ics]] defines the implicit conversion
|
| 6 |
+
sequences and [[over.ics.rank]] defines what it means for one implicit
|
| 7 |
+
conversion sequence to be a better conversion sequence or worse
|
| 8 |
+
conversion sequence than another.
|
| 9 |
+
|
| 10 |
+
Given these definitions, a viable function `F₁` is defined to be a
|
| 11 |
+
*better* function than another viable function `F₂` if for all arguments
|
| 12 |
+
i, ICSⁱ(`F₁`) is not a worse conversion sequence than ICSⁱ(`F₂`), and
|
| 13 |
+
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 return type 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 return type of `F₂` to the destination type
|
| 23 |
+
\[*Example 1*:
|
| 24 |
+
``` cpp
|
| 25 |
+
struct A {
|
| 26 |
+
A();
|
| 27 |
+
operator int();
|
| 28 |
+
operator double();
|
| 29 |
+
} a;
|
| 30 |
+
int i = a; // a.operator int() followed by no conversion is better than
|
| 31 |
+
// a.operator double() followed by a conversion to int
|
| 32 |
+
float x = a; // ambiguous: both possibilities require conversions,
|
| 33 |
+
// and neither is better than the other
|
| 34 |
+
```
|
| 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 `F1` is the same kind of reference (lvalue or
|
| 41 |
+
rvalue) as the reference being initialized, and the return type of
|
| 42 |
+
`F2` is not
|
| 43 |
+
\[*Example 2*:
|
| 44 |
+
``` cpp
|
| 45 |
+
template <class T> struct A {
|
| 46 |
+
operator T&(); // #1
|
| 47 |
+
operator T&&(); // #2
|
| 48 |
+
};
|
| 49 |
+
typedef int Fn();
|
| 50 |
+
A<Fn> a;
|
| 51 |
+
Fn& lf = a; // calls #1
|
| 52 |
+
Fn&& rf = a; // calls #2
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
— *end example*]
|
| 56 |
+
or, if not that,
|
| 57 |
+
- `F1` is not a function template specialization and `F2` is a function
|
| 58 |
+
template specialization, or, if not that,
|
| 59 |
+
- `F1` and `F2` are function template specializations, and the function
|
| 60 |
+
template for `F1` is more specialized than the template for `F2`
|
| 61 |
+
according to the partial ordering rules described in
|
| 62 |
+
[[temp.func.order]], or, if not that,
|
| 63 |
+
- `F1` and `F2` are non-template functions with the same
|
| 64 |
+
parameter-type-lists, and `F1` is more constrained than `F2` according
|
| 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 {
|
| 77 |
+
using A::A;
|
| 78 |
+
B();
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
int main() {
|
| 82 |
+
B b; // OK, B::B()
|
| 83 |
+
}
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
— *end example*]
|
| 87 |
+
or, if not that,
|
| 88 |
+
- `F2` is a rewritten candidate [[over.match.oper]] and `F1` is not
|
| 89 |
+
\[*Example 4*:
|
| 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 |
+
- `F1` and `F2` are rewritten candidates, and `F2` is a synthesized
|
| 101 |
+
candidate with reversed order of parameters and `F1` is not
|
| 102 |
+
\[*Example 5*:
|
| 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 |
+
- `F1` and `F2` are generated from class template argument deduction
|
| 114 |
+
[[over.match.class.deduct]] for a class `D`, and `F2` is generated
|
| 115 |
+
from inheriting constructors from a base class of `D` while `F1` is
|
| 116 |
+
not, and for each explicit function argument, the corresponding
|
| 117 |
+
parameters of `F1` and `F2` are either both ellipses or have the same
|
| 118 |
+
type, or, if not that,
|
| 119 |
+
- `F1` is generated from a *deduction-guide* [[over.match.class.deduct]]
|
| 120 |
+
and `F2` is not, or, if not that,
|
| 121 |
+
- `F1` is the copy deduction candidate [[over.match.class.deduct]] and
|
| 122 |
+
`F2` is not, or, if not that,
|
| 123 |
+
- `F1` is generated from a non-template constructor and `F2` is
|
| 124 |
+
generated from a constructor template.
|
| 125 |
+
\[*Example 6*:
|
| 126 |
+
``` cpp
|
| 127 |
+
template <class T> struct A {
|
| 128 |
+
using value_type = T;
|
| 129 |
+
A(value_type); // #1
|
| 130 |
+
A(const A&); // #2
|
| 131 |
+
A(T, T, int); // #3
|
| 132 |
+
template<class U>
|
| 133 |
+
A(int, T, U); // #4
|
| 134 |
+
// #5 is the copy deduction candidate, A(A)
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
+
A x(1, 2, 3); // uses #3, generated from a non-template constructor
|
| 138 |
+
|
| 139 |
+
template <class T>
|
| 140 |
+
A(T) -> A<T>; // #6, less specialized than #5
|
| 141 |
+
|
| 142 |
+
A a(42); // uses #6 to deduce A<int> and #1 to initialize
|
| 143 |
+
A b = a; // uses #5 to deduce A<int> and #2 to initialize
|
| 144 |
+
|
| 145 |
+
template <class T>
|
| 146 |
+
A(A<T>) -> A<A<T>>; // #7, as specialized as #5
|
| 147 |
+
|
| 148 |
+
A b2 = a; // uses #7 to deduce A<A<int>> and #1 to initialize
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
— *end example*]
|
| 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 7*:
|
| 158 |
+
|
| 159 |
+
``` cpp
|
| 160 |
+
void Fcn(const int*, short);
|
| 161 |
+
void Fcn(int*, int);
|
| 162 |
+
|
| 163 |
+
int i;
|
| 164 |
+
short s = 0;
|
| 165 |
+
|
| 166 |
+
void f() {
|
| 167 |
+
Fcn(&i, s); // is ambiguous because &i → int* is better than &i → const int*
|
| 168 |
+
// but s → short is also better than s → int
|
| 169 |
+
|
| 170 |
+
Fcn(&i, 1L); // calls Fcn(int*, int), because &i → int* is better than &i → const int*
|
| 171 |
+
// and 1L → short and 1L → int are indistinguishable
|
| 172 |
+
|
| 173 |
+
Fcn(&i, 'c'); // calls Fcn(int*, int), because &i → int* is better than &i → const int*
|
| 174 |
+
// and 'c' → int is better than 'c' → short
|
| 175 |
+
}
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
— *end example*]
|
| 179 |
+
|
| 180 |
+
If the best viable function resolves to a function for which multiple
|
| 181 |
+
declarations were found, and if any two of these declarations inhabit
|
| 182 |
+
different scopes and specify a default argument that made the function
|
| 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 |
+
|