- tmp/tmp8xz9bthj/{from.md → to.md} +312 -179
tmp/tmp8xz9bthj/{from.md → to.md}
RENAMED
|
@@ -94,12 +94,12 @@ parameter is
|
|
| 94 |
- “lvalue reference to cv `X`” for functions declared without a
|
| 95 |
*ref-qualifier* or with the `&` *ref-qualifier*
|
| 96 |
- “rvalue reference to cv `X`” for functions declared with the `&&`
|
| 97 |
*ref-qualifier*
|
| 98 |
|
| 99 |
-
where `X` is the class of which the function is a member and cv
|
| 100 |
-
cv-qualification on the member function declaration.
|
| 101 |
|
| 102 |
[*Example 1*: For a `const` member function of class `X`, the extra
|
| 103 |
parameter is assumed to have type “lvalue reference to
|
| 104 |
`const X`”. — *end example*]
|
| 105 |
|
|
@@ -251,63 +251,80 @@ If the function selected by overload resolution is an implicit object
|
|
| 251 |
member function, the program is ill-formed.
|
| 252 |
|
| 253 |
[*Note 2*: The resolution of the address of an overload set in other
|
| 254 |
contexts is described in [[over.over]]. — *end note*]
|
| 255 |
|
| 256 |
-
##### Call to
|
| 257 |
|
| 258 |
Of interest in [[over.call.func]] are only those function calls in
|
| 259 |
-
which the *postfix-expression* ultimately contains an *id-expression*
|
| 260 |
-
that
|
| 261 |
-
nested arbitrarily deep in parentheses,
|
|
|
|
| 262 |
|
| 263 |
``` bnf
|
| 264 |
postfix-expression:
|
| 265 |
postfix-expression '.' id-expression
|
|
|
|
| 266 |
postfix-expression '->' id-expression
|
| 267 |
-
|
|
|
|
|
|
|
| 268 |
```
|
| 269 |
|
| 270 |
These represent two syntactic subcategories of function calls: qualified
|
| 271 |
function calls and unqualified function calls.
|
| 272 |
|
| 273 |
-
In qualified function calls, the function is
|
| 274 |
-
preceded by an `->` or `.`
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
[[over]] assumes that the
|
| 279 |
-
|
|
|
|
| 280 |
|
| 281 |
-
The
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
the
|
|
|
|
|
|
|
| 286 |
|
| 287 |
-
In unqualified function calls, the function is
|
| 288 |
-
*
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
*
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
|
| 301 |
-
if
|
| 302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
|
| 304 |
[*Example 1*:
|
| 305 |
|
| 306 |
``` cpp
|
| 307 |
struct C {
|
| 308 |
-
|
| 309 |
void b() {
|
| 310 |
a(); // OK, (*this).a()
|
| 311 |
}
|
| 312 |
|
| 313 |
void c(this const C&); // #1
|
|
@@ -340,10 +357,19 @@ void d() {
|
|
| 340 |
void k(this int);
|
| 341 |
operator int() const;
|
| 342 |
void m(this const C& c) {
|
| 343 |
c.k(); // OK
|
| 344 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
};
|
| 346 |
```
|
| 347 |
|
| 348 |
— *end example*]
|
| 349 |
|
|
@@ -370,11 +396,11 @@ returning `R`”, or the type “reference to function of (`P₁`, …, `Pₙ`)
|
|
| 370 |
returning `R`”, a *surrogate call function* with the unique name
|
| 371 |
*call-function* and having the form
|
| 372 |
|
| 373 |
``` bnf
|
| 374 |
'R' *call-function* '(' conversion-type-id \ %
|
| 375 |
-
'F, P₁ a₁, …, Pₙ aₙ)' '{ return F (a₁, …, aₙ); }'
|
| 376 |
```
|
| 377 |
|
| 378 |
is also considered as a candidate function. Similarly, surrogate call
|
| 379 |
functions are added to the set of candidate functions for each
|
| 380 |
non-explicit conversion function declared in a base class of `T`
|
|
@@ -453,14 +479,14 @@ However, the operands are sequenced in the order prescribed for the
|
|
| 453 |
built-in operator [[expr.compound]].
|
| 454 |
|
| 455 |
**Table: Relationship between operator and function call notation** <a id="over.match.oper">[over.match.oper]</a>
|
| 456 |
|
| 457 |
| Subclause | Expression | As member function | As non-member function |
|
| 458 |
-
| ------------ | ---------- | ------------------- | ---------------------- |
|
| 459 |
| (a)} |
|
| 460 |
| (a, b)} |
|
| 461 |
-
| [[over.
|
| 462 |
| [[over.sub]] | `a[b]` | `(a).operator[](b)` | |
|
| 463 |
| [[over.ref]] | `a->` | `(a).operator->( )` | |
|
| 464 |
| (a, 0)} |
|
| 465 |
|
| 466 |
|
|
@@ -557,16 +583,12 @@ inline namespace N {
|
|
| 557 |
bool d1 = 0 == D(); // OK, calls reversed #4; #5 does not forbid #4 as a rewrite target
|
| 558 |
```
|
| 559 |
|
| 560 |
— *end example*]
|
| 561 |
|
| 562 |
-
For the built-in assignment operators,
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
- no temporaries are introduced to hold the left operand, and
|
| 566 |
-
- no user-defined conversions are applied to the left operand to achieve
|
| 567 |
-
a type match with the left-most parameter of a built-in candidate.
|
| 568 |
|
| 569 |
For all other operators, no such restrictions apply.
|
| 570 |
|
| 571 |
The set of candidate functions for overload resolution for some operator
|
| 572 |
`@` is the union of the member candidates, the non-member candidates,
|
|
@@ -675,17 +697,18 @@ void B::f() {
|
|
| 675 |
|
| 676 |
When objects of class type are direct-initialized [[dcl.init]],
|
| 677 |
copy-initialized from an expression of the same or a derived class type
|
| 678 |
[[dcl.init]], or default-initialized [[dcl.init]], overload resolution
|
| 679 |
selects the constructor. For direct-initialization or
|
| 680 |
-
default-initialization
|
| 681 |
-
copy-initialization, the candidate functions are all the
|
| 682 |
-
the class of the object being initialized.
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
|
|
|
| 687 |
|
| 688 |
#### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
|
| 689 |
|
| 690 |
Under the conditions specified in [[dcl.init]], as part of a
|
| 691 |
copy-initialization of an object of class type, a user-defined
|
|
@@ -698,11 +721,11 @@ to a possibly cv-qualified class type is determined in terms of a
|
|
| 698 |
corresponding non-reference copy-initialization. — *end note*]
|
| 699 |
|
| 700 |
Assuming that “*cv1* `T`” is the type of the object being initialized,
|
| 701 |
with `T` a class type, the candidate functions are selected as follows:
|
| 702 |
|
| 703 |
-
- The
|
| 704 |
functions.
|
| 705 |
- When the type of the initializer expression is a class type “cv `S`”,
|
| 706 |
conversion functions are considered. The permissible types for
|
| 707 |
non-explicit conversion functions are `T` and any class derived from
|
| 708 |
`T`. When initializing a temporary object [[class.mem]] to be bound to
|
|
@@ -749,14 +772,13 @@ initializer expression. Overload resolution is used to select the
|
|
| 749 |
conversion function to be invoked. Assuming that “reference to *cv1*
|
| 750 |
`T`” is the type of the reference being initialized, the candidate
|
| 751 |
functions are selected as follows:
|
| 752 |
|
| 753 |
- Let R be a set of types including
|
| 754 |
-
- “lvalue reference to *cv2* `T2`” (when
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
an rvalue reference or an lvalue reference to function)
|
| 758 |
|
| 759 |
for any `T2`. The permissible types for non-explicit conversion
|
| 760 |
functions are the members of R where “*cv1* `T`” is
|
| 761 |
reference-compatible [[dcl.init.ref]] with “*cv2* `T2`”. For
|
| 762 |
direct-initialization, the permissible types for explicit conversion
|
|
@@ -789,40 +811,47 @@ resolution selects the constructor in two phases:
|
|
| 789 |
|
| 790 |
In copy-list-initialization, if an explicit constructor is chosen, the
|
| 791 |
initialization is ill-formed.
|
| 792 |
|
| 793 |
[*Note 1*: This differs from other situations
|
| 794 |
-
[[over.match.ctor]], [[over.match.copy]], where only
|
| 795 |
constructors are considered for copy-initialization. This restriction
|
| 796 |
only applies if this initialization is part of the final result of
|
| 797 |
overload resolution. — *end note*]
|
| 798 |
|
| 799 |
#### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
|
| 800 |
|
| 801 |
When resolving a placeholder for a deduced class type
|
| 802 |
-
[[dcl.type.class.deduct]] where the *template-name*
|
| 803 |
-
class template `C`, a set
|
| 804 |
-
the guides of `C`, is formed
|
|
|
|
| 805 |
|
| 806 |
- If `C` is defined, for each constructor of `C`, a function template
|
| 807 |
with the following properties:
|
| 808 |
- The template parameters are the template parameters of `C` followed
|
| 809 |
by the template parameters (including default template arguments) of
|
| 810 |
the constructor, if any.
|
| 811 |
-
- The
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 812 |
- The return type is the class template specialization designated by
|
| 813 |
`C` and template arguments corresponding to the template parameters
|
| 814 |
of `C`.
|
| 815 |
- If `C` is not defined or does not declare any constructors, an
|
| 816 |
additional function template derived as above from a hypothetical
|
| 817 |
constructor `C()`.
|
| 818 |
- An additional function template derived as above from a hypothetical
|
| 819 |
constructor `C(C)`, called the *copy deduction candidate*.
|
| 820 |
- For each *deduction-guide*, a function or function template with the
|
| 821 |
following properties:
|
| 822 |
-
- The template
|
| 823 |
-
of the *deduction-guide*.
|
| 824 |
- The return type is the *simple-template-id* of the
|
| 825 |
*deduction-guide*.
|
| 826 |
|
| 827 |
In addition, if `C` is defined and its definition satisfies the
|
| 828 |
conditions for an aggregate class [[dcl.init.aggr]] with the assumption
|
|
@@ -882,11 +911,11 @@ specialization whose template parameter list is that of `A` and whose
|
|
| 882 |
template argument list is a specialization of `A` with the template
|
| 883 |
argument list of `A` [[temp.dep.type]] having a member typedef `type`
|
| 884 |
designating a template specialization with the template argument list of
|
| 885 |
`A` but with `C` as the template.
|
| 886 |
|
| 887 |
-
[*Note
|
| 888 |
specialization is that of `C`, the template argument list of the
|
| 889 |
specialization is `B`, and the member typedef names `C` with the
|
| 890 |
template argument list of `C`. — *end note*]
|
| 891 |
|
| 892 |
[*Example 1*:
|
|
@@ -939,12 +968,13 @@ J j = { "ghi" }; // error: cannot bind reference to array of unsigned char to
|
|
| 939 |
```
|
| 940 |
|
| 941 |
— *end example*]
|
| 942 |
|
| 943 |
When resolving a placeholder for a deduced class type
|
| 944 |
-
[[dcl.type.simple]] where the *template-name*
|
| 945 |
-
`A`, the *defining-type-id* of `A` must be
|
|
|
|
| 946 |
|
| 947 |
``` bnf
|
| 948 |
typenameₒₚₜ nested-name-specifierₒₚₜ templateₒₚₜ simple-template-id
|
| 949 |
```
|
| 950 |
|
|
@@ -1184,15 +1214,76 @@ parameters to agree in number with the arguments in the list.
|
|
| 1184 |
- A candidate function having fewer than m parameters is viable only if
|
| 1185 |
it has an ellipsis in its parameter list [[dcl.fct]]. For the purposes
|
| 1186 |
of overload resolution, any argument for which there is no
|
| 1187 |
corresponding parameter is considered to “match the ellipsis”
|
| 1188 |
[[over.ics.ellipsis]].
|
| 1189 |
-
- A candidate function having more than m parameters is viable only
|
| 1190 |
-
|
| 1191 |
-
|
| 1192 |
-
|
| 1193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1194 |
|
| 1195 |
Second, for a function to be viable, if it has associated constraints
|
| 1196 |
[[temp.constr.decl]], those constraints shall be satisfied
|
| 1197 |
[[temp.constr.constr]].
|
| 1198 |
|
|
@@ -1223,14 +1314,14 @@ then
|
|
| 1223 |
|
| 1224 |
- for some argument j, ICSʲ(`F₁`) is a better conversion sequence than
|
| 1225 |
ICSʲ(`F₂`), or, if not that,
|
| 1226 |
- the context is an initialization by user-defined conversion (see
|
| 1227 |
[[dcl.init]], [[over.match.conv]], and [[over.match.ref]]) and the
|
| 1228 |
-
standard conversion sequence from the
|
| 1229 |
destination type (i.e., the type of the entity being initialized) is a
|
| 1230 |
better conversion sequence than the standard conversion sequence from
|
| 1231 |
-
the
|
| 1232 |
\[*Example 1*:
|
| 1233 |
``` cpp
|
| 1234 |
struct A {
|
| 1235 |
A();
|
| 1236 |
operator int();
|
|
@@ -1244,13 +1335,13 @@ then
|
|
| 1244 |
|
| 1245 |
— *end example*]
|
| 1246 |
or, if not that,
|
| 1247 |
- the context is an initialization by conversion function for direct
|
| 1248 |
reference binding [[over.match.ref]] of a reference to function type,
|
| 1249 |
-
the return type of `
|
| 1250 |
rvalue) as the reference being initialized, and the return type of
|
| 1251 |
-
`
|
| 1252 |
\[*Example 2*:
|
| 1253 |
``` cpp
|
| 1254 |
template <class T> struct A {
|
| 1255 |
operator T&(); // #1
|
| 1256 |
operator T&&(); // #2
|
|
@@ -1261,24 +1352,38 @@ then
|
|
| 1261 |
Fn&& rf = a; // calls #2
|
| 1262 |
```
|
| 1263 |
|
| 1264 |
— *end example*]
|
| 1265 |
or, if not that,
|
| 1266 |
-
- `
|
| 1267 |
template specialization, or, if not that,
|
| 1268 |
-
- `
|
| 1269 |
-
template for `
|
| 1270 |
according to the partial ordering rules described in
|
| 1271 |
[[temp.func.order]], or, if not that,
|
| 1272 |
-
- `
|
| 1273 |
-
|
| 1274 |
-
|
| 1275 |
-
|
| 1276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1277 |
base class `B` of `D`, and for all arguments the corresponding
|
| 1278 |
-
parameters of `
|
| 1279 |
-
\[*Example
|
| 1280 |
``` cpp
|
| 1281 |
struct A {
|
| 1282 |
A(int = 0);
|
| 1283 |
};
|
| 1284 |
|
|
@@ -1292,48 +1397,48 @@ then
|
|
| 1292 |
}
|
| 1293 |
```
|
| 1294 |
|
| 1295 |
— *end example*]
|
| 1296 |
or, if not that,
|
| 1297 |
-
- `
|
| 1298 |
-
\[*Example
|
| 1299 |
``` cpp
|
| 1300 |
struct S {
|
| 1301 |
friend auto operator<=>(const S&, const S&) = default; // #1
|
| 1302 |
friend bool operator<(const S&, const S&); // #2
|
| 1303 |
};
|
| 1304 |
bool b = S() < S(); // calls #2
|
| 1305 |
```
|
| 1306 |
|
| 1307 |
— *end example*]
|
| 1308 |
or, if not that,
|
| 1309 |
-
- `
|
| 1310 |
-
candidate with reversed order of parameters and `
|
| 1311 |
-
\[*Example
|
| 1312 |
``` cpp
|
| 1313 |
struct S {
|
| 1314 |
friend std::weak_ordering operator<=>(const S&, int); // #1
|
| 1315 |
friend std::weak_ordering operator<=>(int, const S&); // #2
|
| 1316 |
};
|
| 1317 |
bool b = 1 < S(); // calls #2
|
| 1318 |
```
|
| 1319 |
|
| 1320 |
— *end example*]
|
| 1321 |
-
or, if not that
|
| 1322 |
-
- `
|
| 1323 |
-
[[over.match.class.deduct]] for a class `D`, and `
|
| 1324 |
-
from inheriting constructors from a base class of `D` while `
|
| 1325 |
not, and for each explicit function argument, the corresponding
|
| 1326 |
-
parameters of `
|
| 1327 |
type, or, if not that,
|
| 1328 |
-
- `
|
| 1329 |
-
and `
|
| 1330 |
-
- `
|
| 1331 |
-
`
|
| 1332 |
-
- `
|
| 1333 |
generated from a constructor template.
|
| 1334 |
-
\[*Example
|
| 1335 |
``` cpp
|
| 1336 |
template <class T> struct A {
|
| 1337 |
using value_type = T;
|
| 1338 |
A(value_type); // #1
|
| 1339 |
A(const A&); // #2
|
|
@@ -1361,11 +1466,11 @@ then
|
|
| 1361 |
|
| 1362 |
If there is exactly one viable function that is a better function than
|
| 1363 |
all other viable functions, then it is the one selected by overload
|
| 1364 |
resolution; otherwise the call is ill-formed.[^7]
|
| 1365 |
|
| 1366 |
-
[*Example
|
| 1367 |
|
| 1368 |
``` cpp
|
| 1369 |
void Fcn(const int*, short);
|
| 1370 |
void Fcn(int*, int);
|
| 1371 |
|
|
@@ -1384,35 +1489,13 @@ void f() {
|
|
| 1384 |
}
|
| 1385 |
```
|
| 1386 |
|
| 1387 |
— *end example*]
|
| 1388 |
|
| 1389 |
-
If the best viable function
|
| 1390 |
-
|
| 1391 |
-
|
| 1392 |
-
viable, the program is ill-formed.
|
| 1393 |
-
|
| 1394 |
-
[*Example 8*:
|
| 1395 |
-
|
| 1396 |
-
``` cpp
|
| 1397 |
-
namespace A {
|
| 1398 |
-
extern "C" void f(int = 5);
|
| 1399 |
-
}
|
| 1400 |
-
namespace B {
|
| 1401 |
-
extern "C" void f(int = 5);
|
| 1402 |
-
}
|
| 1403 |
-
|
| 1404 |
-
using A::f;
|
| 1405 |
-
using B::f;
|
| 1406 |
-
|
| 1407 |
-
void use() {
|
| 1408 |
-
f(3); // OK, default argument was not used for viability
|
| 1409 |
-
f(); // error: found default argument twice
|
| 1410 |
-
}
|
| 1411 |
-
```
|
| 1412 |
-
|
| 1413 |
-
— *end example*]
|
| 1414 |
|
| 1415 |
#### Implicit conversion sequences <a id="over.best.ics">[[over.best.ics]]</a>
|
| 1416 |
|
| 1417 |
##### General <a id="over.best.ics.general">[[over.best.ics.general]]</a>
|
| 1418 |
|
|
@@ -1425,17 +1508,17 @@ single expression [[dcl.init]], [[dcl.init.ref]].
|
|
| 1425 |
|
| 1426 |
Implicit conversion sequences are concerned only with the type,
|
| 1427 |
cv-qualification, and value category of the argument and how these are
|
| 1428 |
converted to match the corresponding properties of the parameter.
|
| 1429 |
|
| 1430 |
-
[*Note 1*: Other properties, such as the lifetime, storage
|
| 1431 |
-
alignment, accessibility of the argument, whether the argument
|
| 1432 |
-
bit-field, and whether a function is deleted
|
| 1433 |
-
ignored. So, although an implicit conversion
|
| 1434 |
-
a given argument-parameter pair, the
|
| 1435 |
-
parameter might still be ill-formed
|
| 1436 |
-
analysis. — *end note*]
|
| 1437 |
|
| 1438 |
A well-formed implicit conversion sequence is one of the following
|
| 1439 |
forms:
|
| 1440 |
|
| 1441 |
- a standard conversion sequence [[over.ics.scs]],
|
|
@@ -1492,40 +1575,40 @@ parameter.
|
|
| 1492 |
[*Note 3*: When the parameter has a class type, this is a conceptual
|
| 1493 |
conversion defined for the purposes of [[over]]; the actual
|
| 1494 |
initialization is defined in terms of constructors and is not a
|
| 1495 |
conversion. — *end note*]
|
| 1496 |
|
| 1497 |
-
|
| 1498 |
-
|
| 1499 |
-
|
| 1500 |
-
|
| 1501 |
-
|
| 1502 |
-
|
| 1503 |
-
|
| 1504 |
-
|
| 1505 |
-
When the parameter has a class type and the argument expression has the
|
| 1506 |
-
same type, the implicit conversion sequence is an identity conversion.
|
| 1507 |
-
When the parameter has a class type and the argument expression has a
|
| 1508 |
-
derived class type, the implicit conversion sequence is a
|
| 1509 |
-
derived-to-base conversion from the derived class to the base class. A
|
| 1510 |
-
derived-to-base conversion has Conversion rank [[over.ics.scs]].
|
| 1511 |
|
| 1512 |
[*Note 4*: There is no such standard conversion; this derived-to-base
|
| 1513 |
conversion exists only in the description of implicit conversion
|
| 1514 |
sequences. — *end note*]
|
| 1515 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1516 |
When the parameter is the implicit object parameter of a static member
|
| 1517 |
function, the implicit conversion sequence is a standard conversion
|
| 1518 |
sequence that is neither better nor worse than any other standard
|
| 1519 |
conversion sequence.
|
| 1520 |
|
| 1521 |
In all contexts, when converting to the implicit object parameter or
|
| 1522 |
when converting to the left operand of an assignment operation only
|
| 1523 |
standard conversion sequences are allowed.
|
| 1524 |
|
| 1525 |
-
[*Note 5*: When
|
| 1526 |
-
user-defined conversion sequences
|
| 1527 |
|
| 1528 |
If no conversions are required to match an argument to a parameter type,
|
| 1529 |
the implicit conversion sequence is the standard conversion sequence
|
| 1530 |
consisting of the identity conversion [[over.ics.scs]].
|
| 1531 |
|
|
@@ -1632,11 +1715,11 @@ the special rules for initialization by user-defined conversion apply
|
|
| 1632 |
when selecting the best user-defined conversion for a user-defined
|
| 1633 |
conversion sequence (see [[over.match.best]] and [[over.best.ics]]).
|
| 1634 |
|
| 1635 |
If the user-defined conversion is specified by a specialization of a
|
| 1636 |
conversion function template, the second standard conversion sequence
|
| 1637 |
-
shall have
|
| 1638 |
|
| 1639 |
A conversion of an expression of class type to the same class type is
|
| 1640 |
given Exact Match rank, and a conversion of an expression of class type
|
| 1641 |
to a base class of that type is given Conversion rank, in spite of the
|
| 1642 |
fact that a constructor (i.e., a user-defined conversion function) is
|
|
@@ -1648,34 +1731,47 @@ An ellipsis conversion sequence occurs when an argument in a function
|
|
| 1648 |
call is matched with the ellipsis parameter specification of the
|
| 1649 |
function called (see [[expr.call]]).
|
| 1650 |
|
| 1651 |
##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
|
| 1652 |
|
| 1653 |
-
When a parameter of
|
| 1654 |
-
|
| 1655 |
-
|
| 1656 |
-
|
| 1657 |
-
sequence is a derived-to-base
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1658 |
|
| 1659 |
[*Example 4*:
|
| 1660 |
|
| 1661 |
``` cpp
|
| 1662 |
struct A {};
|
| 1663 |
struct B : public A {} b;
|
| 1664 |
int f(A&);
|
| 1665 |
int f(B&);
|
| 1666 |
int i = f(b); // calls f(B&), an exact match, rather than f(A&), a conversion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1667 |
```
|
| 1668 |
|
| 1669 |
— *end example*]
|
| 1670 |
|
| 1671 |
If the parameter binds directly to the result of applying a conversion
|
| 1672 |
function to the argument expression, the implicit conversion sequence is
|
| 1673 |
a user-defined conversion sequence [[over.ics.user]] whose second
|
| 1674 |
-
standard conversion sequence is
|
| 1675 |
-
conversion function returns an entity of a type that is a derived class
|
| 1676 |
-
of the parameter type, a derived-to-base conversion.
|
| 1677 |
|
| 1678 |
When a parameter of reference type is not bound directly to an argument
|
| 1679 |
expression, the conversion sequence is the one required to convert the
|
| 1680 |
argument expression to the referenced type according to
|
| 1681 |
[[over.best.ics]]. Conceptually, this conversion sequence corresponds to
|
|
@@ -1685,11 +1781,11 @@ the initialization itself and does not constitute a conversion.
|
|
| 1685 |
|
| 1686 |
Except for an implicit object parameter, for which see
|
| 1687 |
[[over.match.funcs]], an implicit conversion sequence cannot be formed
|
| 1688 |
if it requires binding an lvalue reference other than a reference to a
|
| 1689 |
non-volatile `const` type to an rvalue or binding an rvalue reference to
|
| 1690 |
-
an lvalue
|
| 1691 |
|
| 1692 |
[*Note 9*: This means, for example, that a candidate function cannot be
|
| 1693 |
a viable function if it has a non-`const` lvalue reference parameter
|
| 1694 |
(other than the implicit object parameter) and the corresponding
|
| 1695 |
argument would require a temporary to be created to initialize the
|
|
@@ -1712,16 +1808,17 @@ non-`const` lvalue reference to a bit-field
|
|
| 1712 |
|
| 1713 |
When an argument is an initializer list [[dcl.init.list]], it is not an
|
| 1714 |
expression and special rules apply for converting it to a parameter
|
| 1715 |
type.
|
| 1716 |
|
| 1717 |
-
If the initializer list is a *designated-initializer-list*
|
| 1718 |
-
is
|
| 1719 |
-
|
| 1720 |
-
|
| 1721 |
-
|
| 1722 |
-
|
|
|
|
| 1723 |
|
| 1724 |
[*Note 10*:
|
| 1725 |
|
| 1726 |
Aggregate initialization does not require that the members are declared
|
| 1727 |
in designation order. If, after overload resolution, the order does not
|
|
@@ -1777,11 +1874,11 @@ f( {1,2,3} ); // OK, f(initializer_list<int>) identity convers
|
|
| 1777 |
f( {'a','b'} ); // OK, f(initializer_list<int>) integral promotion
|
| 1778 |
f( {1.0} ); // error: narrowing
|
| 1779 |
|
| 1780 |
struct A {
|
| 1781 |
A(std::initializer_list<double>); // #1
|
| 1782 |
-
A(std::initializer_list<complex<double>>);
|
| 1783 |
A(std::initializer_list<std::string>); // #3
|
| 1784 |
};
|
| 1785 |
A a{ 1.0,2.0 }; // OK, uses #1
|
| 1786 |
|
| 1787 |
void g(A);
|
|
@@ -2025,12 +2122,12 @@ conversion sequences unless one of the following rules applies:
|
|
| 2025 |
```
|
| 2026 |
|
| 2027 |
— *end example*]
|
| 2028 |
or, if not that,
|
| 2029 |
- `S1` and `S2` include reference bindings [[dcl.init.ref]] and `S1`
|
| 2030 |
-
binds an lvalue reference to
|
| 2031 |
-
rvalue reference to
|
| 2032 |
\[*Example 4*:
|
| 2033 |
``` cpp
|
| 2034 |
int f(void(&)()); // #1
|
| 2035 |
int f(void(&&)()); // #2
|
| 2036 |
void g();
|
|
@@ -2038,28 +2135,33 @@ conversion sequences unless one of the following rules applies:
|
|
| 2038 |
```
|
| 2039 |
|
| 2040 |
— *end example*]
|
| 2041 |
or, if not that,
|
| 2042 |
- `S1` and `S2` differ only in their qualification conversion
|
| 2043 |
-
[[conv.qual]] and yield similar types `T1` and `T2`, respectively
|
| 2044 |
-
where
|
|
|
|
|
|
|
|
|
|
| 2045 |
\[*Example 5*:
|
| 2046 |
``` cpp
|
| 2047 |
int f(const volatile int *);
|
| 2048 |
int f(const int *);
|
| 2049 |
int i;
|
| 2050 |
int j = f(&i); // calls f(const int*)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2051 |
```
|
| 2052 |
|
| 2053 |
— *end example*]
|
| 2054 |
or, if not that,
|
| 2055 |
- `S1`
|
| 2056 |
-
and `S2`
|
| 2057 |
-
|
| 2058 |
-
|
| 2059 |
-
`S2` refers is more cv-qualified than the type to which the
|
| 2060 |
-
reference initialized by `S1` refers.
|
| 2061 |
\[*Example 6*:
|
| 2062 |
``` cpp
|
| 2063 |
int f(const int &);
|
| 2064 |
int f(int &);
|
| 2065 |
int g(const int &);
|
|
@@ -2075,20 +2177,51 @@ conversion sequences unless one of the following rules applies:
|
|
| 2075 |
};
|
| 2076 |
void g(const X& a, X b) {
|
| 2077 |
a.f(); // calls X::f() const
|
| 2078 |
b.f(); // calls X::f()
|
| 2079 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2080 |
```
|
| 2081 |
|
| 2082 |
— *end example*]
|
| 2083 |
- User-defined conversion sequence `U1` is a better conversion sequence
|
| 2084 |
than another user-defined conversion sequence `U2` if they contain the
|
| 2085 |
same user-defined conversion function or constructor or they
|
| 2086 |
initialize the same class in an aggregate initialization and in either
|
| 2087 |
case the second standard conversion sequence of `U1` is better than
|
| 2088 |
the second standard conversion sequence of `U2`.
|
| 2089 |
-
\[*Example
|
| 2090 |
``` cpp
|
| 2091 |
struct A {
|
| 2092 |
operator short();
|
| 2093 |
} a;
|
| 2094 |
int f(int);
|
|
@@ -2116,11 +2249,11 @@ indistinguishable unless one of the following rules applies:
|
|
| 2116 |
to the rank of `FP2`, and
|
| 2117 |
- `T3` is not a floating-point type, or `T3` is a floating-point type
|
| 2118 |
whose rank is not equal to the rank of `FP1`, or the floating-point
|
| 2119 |
conversion subrank [[conv.rank]] of `FP2` is greater than the
|
| 2120 |
subrank of `T3`.
|
| 2121 |
-
\[*Example
|
| 2122 |
``` cpp
|
| 2123 |
int f(std::float32_t);
|
| 2124 |
int f(std::float64_t);
|
| 2125 |
int f(long long);
|
| 2126 |
float x;
|
|
@@ -2137,11 +2270,11 @@ indistinguishable unless one of the following rules applies:
|
|
| 2137 |
of `B*` to `void*`.
|
| 2138 |
- If class `B` is derived directly or indirectly from class `A` and
|
| 2139 |
class `C` is derived directly or indirectly from `B`,
|
| 2140 |
- conversion of `C*` to `B*` is better than conversion of `C*` to
|
| 2141 |
`A*`,
|
| 2142 |
-
\[*Example
|
| 2143 |
``` cpp
|
| 2144 |
struct A {};
|
| 2145 |
struct B : public A {};
|
| 2146 |
struct C : public B {};
|
| 2147 |
C* pc;
|
|
|
|
| 94 |
- “lvalue reference to cv `X`” for functions declared without a
|
| 95 |
*ref-qualifier* or with the `&` *ref-qualifier*
|
| 96 |
- “rvalue reference to cv `X`” for functions declared with the `&&`
|
| 97 |
*ref-qualifier*
|
| 98 |
|
| 99 |
+
where `X` is the class of which the function is a direct member and cv
|
| 100 |
+
is the cv-qualification on the member function declaration.
|
| 101 |
|
| 102 |
[*Example 1*: For a `const` member function of class `X`, the extra
|
| 103 |
parameter is assumed to have type “lvalue reference to
|
| 104 |
`const X`”. — *end example*]
|
| 105 |
|
|
|
|
| 251 |
member function, the program is ill-formed.
|
| 252 |
|
| 253 |
[*Note 2*: The resolution of the address of an overload set in other
|
| 254 |
contexts is described in [[over.over]]. — *end note*]
|
| 255 |
|
| 256 |
+
##### Call to designated function <a id="over.call.func">[[over.call.func]]</a>
|
| 257 |
|
| 258 |
Of interest in [[over.call.func]] are only those function calls in
|
| 259 |
+
which the *postfix-expression* ultimately contains an *id-expression* or
|
| 260 |
+
*splice-expression* that designates one or more functions. Such a
|
| 261 |
+
*postfix-expression*, perhaps nested arbitrarily deep in parentheses,
|
| 262 |
+
has one of the following forms:
|
| 263 |
|
| 264 |
``` bnf
|
| 265 |
postfix-expression:
|
| 266 |
postfix-expression '.' id-expression
|
| 267 |
+
postfix-expression '.' splice-expression
|
| 268 |
postfix-expression '->' id-expression
|
| 269 |
+
postfix-expression '->' splice-expression
|
| 270 |
+
id-expression
|
| 271 |
+
splice-expression
|
| 272 |
```
|
| 273 |
|
| 274 |
These represent two syntactic subcategories of function calls: qualified
|
| 275 |
function calls and unqualified function calls.
|
| 276 |
|
| 277 |
+
In qualified function calls, the function is designated by an
|
| 278 |
+
*id-expression* or *splice-expression* E preceded by an `->` or `.`
|
| 279 |
+
operator. Since the construct `A->B` is generally equivalent to
|
| 280 |
+
`(*A).B`, the rest of [[over]] assumes, without loss of generality, that
|
| 281 |
+
all member function calls have been normalized to the form that uses an
|
| 282 |
+
object and the `.` operator. Furthermore, [[over]] assumes that the
|
| 283 |
+
*postfix-expression* that is the left operand of the `.` operator has
|
| 284 |
+
type “cv `T`” where `T` denotes a class.[^2]
|
| 285 |
|
| 286 |
+
The set of candidate functions either is the set found by name lookup
|
| 287 |
+
[[class.member.lookup]] if E is an *id-expression* or is the set
|
| 288 |
+
determined as specified in [[expr.prim.splice]] if E is a
|
| 289 |
+
*splice-expression*. The argument list is the *expression-list* in the
|
| 290 |
+
call augmented by the addition of the left operand of the `.` operator
|
| 291 |
+
in the normalized member function call as the implied object argument
|
| 292 |
+
[[over.match.funcs]].
|
| 293 |
|
| 294 |
+
In unqualified function calls, the function is designated by an
|
| 295 |
+
*id-expression* or a *splice-expression* E. The set of candidate
|
| 296 |
+
functions either is the set found by name lookup [[basic.lookup]] if E
|
| 297 |
+
is an *id-expression* or is the set determined as specified in
|
| 298 |
+
[[expr.prim.splice]] if E is a *splice-expression*. The set of candidate
|
| 299 |
+
functions consists either entirely of non-member functions or entirely
|
| 300 |
+
of member functions of some class `T`. In the former case or if E is
|
| 301 |
+
either a *splice-expression* or the address of an overload set, the
|
| 302 |
+
argument list is the same as the *expression-list* in the call.
|
| 303 |
+
Otherwise, the argument list is the *expression-list* in the call
|
| 304 |
+
augmented by the addition of an implied object argument as in a
|
| 305 |
+
qualified function call. If the current class is, or is derived from,
|
| 306 |
+
`T`, and the keyword `this` [[expr.prim.this]] refers to it,
|
| 307 |
|
| 308 |
+
- if the unqualified function call appears in a precondition assertion
|
| 309 |
+
of a constructor or a postcondition assertion of a destructor and
|
| 310 |
+
overload resolution selects a non-static member function, the call is
|
| 311 |
+
ill-formed;
|
| 312 |
+
- otherwise, the implied object argument is `(*this)`.
|
| 313 |
+
|
| 314 |
+
Otherwise,
|
| 315 |
+
|
| 316 |
+
- if overload resolution selects a non-static member function, the call
|
| 317 |
+
is ill-formed;
|
| 318 |
+
- otherwise, a contrived object of type `T` becomes the implied object
|
| 319 |
+
argument.[^3]
|
| 320 |
|
| 321 |
[*Example 1*:
|
| 322 |
|
| 323 |
``` cpp
|
| 324 |
struct C {
|
| 325 |
+
bool a();
|
| 326 |
void b() {
|
| 327 |
a(); // OK, (*this).a()
|
| 328 |
}
|
| 329 |
|
| 330 |
void c(this const C&); // #1
|
|
|
|
| 357 |
void k(this int);
|
| 358 |
operator int() const;
|
| 359 |
void m(this const C& c) {
|
| 360 |
c.k(); // OK
|
| 361 |
}
|
| 362 |
+
|
| 363 |
+
C()
|
| 364 |
+
pre(a()) // error: implied this in constructor precondition
|
| 365 |
+
pre(this->a()) // OK
|
| 366 |
+
post(a()); // OK
|
| 367 |
+
~C()
|
| 368 |
+
pre(a()) // OK
|
| 369 |
+
post(a()) // error: implied this in destructor postcondition
|
| 370 |
+
post(this->a()); // OK
|
| 371 |
};
|
| 372 |
```
|
| 373 |
|
| 374 |
— *end example*]
|
| 375 |
|
|
|
|
| 396 |
returning `R`”, a *surrogate call function* with the unique name
|
| 397 |
*call-function* and having the form
|
| 398 |
|
| 399 |
``` bnf
|
| 400 |
'R' *call-function* '(' conversion-type-id \ %
|
| 401 |
+
'F, P₁ a₁, …, Pₙ aₙ)' '{' return 'F (a₁, …, aₙ); }'
|
| 402 |
```
|
| 403 |
|
| 404 |
is also considered as a candidate function. Similarly, surrogate call
|
| 405 |
functions are added to the set of candidate functions for each
|
| 406 |
non-explicit conversion function declared in a base class of `T`
|
|
|
|
| 479 |
built-in operator [[expr.compound]].
|
| 480 |
|
| 481 |
**Table: Relationship between operator and function call notation** <a id="over.match.oper">[over.match.oper]</a>
|
| 482 |
|
| 483 |
| Subclause | Expression | As member function | As non-member function |
|
| 484 |
+
| --------------- | ---------- | ------------------- | ---------------------- |
|
| 485 |
| (a)} |
|
| 486 |
| (a, b)} |
|
| 487 |
+
| [[over.assign]] | `a=b` | `(a).operator= (b)` | |
|
| 488 |
| [[over.sub]] | `a[b]` | `(a).operator[](b)` | |
|
| 489 |
| [[over.ref]] | `a->` | `(a).operator->( )` | |
|
| 490 |
| (a, 0)} |
|
| 491 |
|
| 492 |
|
|
|
|
| 583 |
bool d1 = 0 == D(); // OK, calls reversed #4; #5 does not forbid #4 as a rewrite target
|
| 584 |
```
|
| 585 |
|
| 586 |
— *end example*]
|
| 587 |
|
| 588 |
+
For the first parameter of the built-in assignment operators, only
|
| 589 |
+
standard conversion sequences [[over.ics.scs]] are considered.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 590 |
|
| 591 |
For all other operators, no such restrictions apply.
|
| 592 |
|
| 593 |
The set of candidate functions for overload resolution for some operator
|
| 594 |
`@` is the union of the member candidates, the non-member candidates,
|
|
|
|
| 697 |
|
| 698 |
When objects of class type are direct-initialized [[dcl.init]],
|
| 699 |
copy-initialized from an expression of the same or a derived class type
|
| 700 |
[[dcl.init]], or default-initialized [[dcl.init]], overload resolution
|
| 701 |
selects the constructor. For direct-initialization or
|
| 702 |
+
default-initialization (including default-initialization in the context
|
| 703 |
+
of copy-list-initialization), the candidate functions are all the
|
| 704 |
+
constructors of the class of the object being initialized. Otherwise,
|
| 705 |
+
the candidate functions are all the non-explicit constructors
|
| 706 |
+
[[class.conv.ctor]] of that class. The argument list is the
|
| 707 |
+
*expression-list* or *assignment-expression* of the *initializer*. For
|
| 708 |
+
default-initialization in the context of copy-list-initialization, if an
|
| 709 |
+
explicit constructor is chosen, the initialization is ill-formed.
|
| 710 |
|
| 711 |
#### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
|
| 712 |
|
| 713 |
Under the conditions specified in [[dcl.init]], as part of a
|
| 714 |
copy-initialization of an object of class type, a user-defined
|
|
|
|
| 721 |
corresponding non-reference copy-initialization. — *end note*]
|
| 722 |
|
| 723 |
Assuming that “*cv1* `T`” is the type of the object being initialized,
|
| 724 |
with `T` a class type, the candidate functions are selected as follows:
|
| 725 |
|
| 726 |
+
- The non-explicit constructors [[class.conv.ctor]] of `T` are candidate
|
| 727 |
functions.
|
| 728 |
- When the type of the initializer expression is a class type “cv `S`”,
|
| 729 |
conversion functions are considered. The permissible types for
|
| 730 |
non-explicit conversion functions are `T` and any class derived from
|
| 731 |
`T`. When initializing a temporary object [[class.mem]] to be bound to
|
|
|
|
| 772 |
conversion function to be invoked. Assuming that “reference to *cv1*
|
| 773 |
`T`” is the type of the reference being initialized, the candidate
|
| 774 |
functions are selected as follows:
|
| 775 |
|
| 776 |
- Let R be a set of types including
|
| 777 |
+
- “lvalue reference to *cv2* `T2`” (when converting to an lvalue) and
|
| 778 |
+
- “*cv2* `T2`” and “rvalue reference to *cv2* `T2`” (when converting
|
| 779 |
+
to an rvalue or an lvalue of function type)
|
|
|
|
| 780 |
|
| 781 |
for any `T2`. The permissible types for non-explicit conversion
|
| 782 |
functions are the members of R where “*cv1* `T`” is
|
| 783 |
reference-compatible [[dcl.init.ref]] with “*cv2* `T2`”. For
|
| 784 |
direct-initialization, the permissible types for explicit conversion
|
|
|
|
| 811 |
|
| 812 |
In copy-list-initialization, if an explicit constructor is chosen, the
|
| 813 |
initialization is ill-formed.
|
| 814 |
|
| 815 |
[*Note 1*: This differs from other situations
|
| 816 |
+
[[over.match.ctor]], [[over.match.copy]], where only non-explicit
|
| 817 |
constructors are considered for copy-initialization. This restriction
|
| 818 |
only applies if this initialization is part of the final result of
|
| 819 |
overload resolution. — *end note*]
|
| 820 |
|
| 821 |
#### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
|
| 822 |
|
| 823 |
When resolving a placeholder for a deduced class type
|
| 824 |
+
[[dcl.type.class.deduct]] where the *template-name* or
|
| 825 |
+
*splice-type-specifier* designates a primary class template `C`, a set
|
| 826 |
+
of functions and function templates, called the guides of `C`, is formed
|
| 827 |
+
comprising:
|
| 828 |
|
| 829 |
- If `C` is defined, for each constructor of `C`, a function template
|
| 830 |
with the following properties:
|
| 831 |
- The template parameters are the template parameters of `C` followed
|
| 832 |
by the template parameters (including default template arguments) of
|
| 833 |
the constructor, if any.
|
| 834 |
+
- The associated constraints [[temp.constr.decl]] are the conjunction
|
| 835 |
+
of the associated constraints of `C` and the associated constraints
|
| 836 |
+
of the constructor, if any. \[*Note 1*: A *constraint-expression* in
|
| 837 |
+
the *template-head* of `C` is checked for satisfaction before any
|
| 838 |
+
constraints from the *template-head* or trailing *requires-clause*
|
| 839 |
+
of the constructor. — *end note*]
|
| 840 |
+
- The *parameter-declaration-clause* is that of the constructor.
|
| 841 |
- The return type is the class template specialization designated by
|
| 842 |
`C` and template arguments corresponding to the template parameters
|
| 843 |
of `C`.
|
| 844 |
- If `C` is not defined or does not declare any constructors, an
|
| 845 |
additional function template derived as above from a hypothetical
|
| 846 |
constructor `C()`.
|
| 847 |
- An additional function template derived as above from a hypothetical
|
| 848 |
constructor `C(C)`, called the *copy deduction candidate*.
|
| 849 |
- For each *deduction-guide*, a function or function template with the
|
| 850 |
following properties:
|
| 851 |
+
- The *template-head*, if any, and *parameter-declaration-clause* are
|
| 852 |
+
those of the *deduction-guide*.
|
| 853 |
- The return type is the *simple-template-id* of the
|
| 854 |
*deduction-guide*.
|
| 855 |
|
| 856 |
In addition, if `C` is defined and its definition satisfies the
|
| 857 |
conditions for an aggregate class [[dcl.init.aggr]] with the assumption
|
|
|
|
| 911 |
template argument list is a specialization of `A` with the template
|
| 912 |
argument list of `A` [[temp.dep.type]] having a member typedef `type`
|
| 913 |
designating a template specialization with the template argument list of
|
| 914 |
`A` but with `C` as the template.
|
| 915 |
|
| 916 |
+
[*Note 2*: Equivalently, the template parameter list of the
|
| 917 |
specialization is that of `C`, the template argument list of the
|
| 918 |
specialization is `B`, and the member typedef names `C` with the
|
| 919 |
template argument list of `C`. — *end note*]
|
| 920 |
|
| 921 |
[*Example 1*:
|
|
|
|
| 968 |
```
|
| 969 |
|
| 970 |
— *end example*]
|
| 971 |
|
| 972 |
When resolving a placeholder for a deduced class type
|
| 973 |
+
[[dcl.type.simple]] where the *template-name* or *splice-type-specifier*
|
| 974 |
+
designates an alias template `A`, the *defining-type-id* of `A` must be
|
| 975 |
+
of the form
|
| 976 |
|
| 977 |
``` bnf
|
| 978 |
typenameₒₚₜ nested-name-specifierₒₚₜ templateₒₚₜ simple-template-id
|
| 979 |
```
|
| 980 |
|
|
|
|
| 1214 |
- A candidate function having fewer than m parameters is viable only if
|
| 1215 |
it has an ellipsis in its parameter list [[dcl.fct]]. For the purposes
|
| 1216 |
of overload resolution, any argument for which there is no
|
| 1217 |
corresponding parameter is considered to “match the ellipsis”
|
| 1218 |
[[over.ics.ellipsis]].
|
| 1219 |
+
- A candidate function `C` having more than m parameters is viable only
|
| 1220 |
+
if the set of scopes G, as defined below, is not empty. G consists of
|
| 1221 |
+
every scope X that satisfies all of the following:
|
| 1222 |
+
- There is a declaration of `C`, whose host scope is X, considered by
|
| 1223 |
+
the overload resolution.
|
| 1224 |
+
- For every $k^\textrm{th}$ parameter P where k \> m, there is a
|
| 1225 |
+
reachable declaration, whose host scope is X, that specifies a
|
| 1226 |
+
default argument [[dcl.fct.default]] for P.
|
| 1227 |
+
|
| 1228 |
+
If `C` is selected as the best viable function [[over.match.best]]:
|
| 1229 |
+
- G shall contain exactly one scope (call it S).
|
| 1230 |
+
- If the candidates are denoted by a *splice-expression*, then S shall
|
| 1231 |
+
not be a block scope.
|
| 1232 |
+
- The default arguments used in the call to `C` are the default
|
| 1233 |
+
arguments specified by the reachable declarations whose host scope
|
| 1234 |
+
is S.
|
| 1235 |
+
|
| 1236 |
+
For the purposes of overload resolution, the parameter list is
|
| 1237 |
+
truncated on the right, so that there are exactly m parameters.
|
| 1238 |
+
|
| 1239 |
+
[*Example 1*:
|
| 1240 |
+
|
| 1241 |
+
``` cpp
|
| 1242 |
+
namespace A {
|
| 1243 |
+
extern "C" void f(int, int = 5);
|
| 1244 |
+
extern "C" void f(int = 6, int);
|
| 1245 |
+
}
|
| 1246 |
+
namespace B {
|
| 1247 |
+
extern "C" void f(int, int = 7);
|
| 1248 |
+
}
|
| 1249 |
+
|
| 1250 |
+
void use() {
|
| 1251 |
+
[:^^A::f:](3, 4); // OK, default argument was not used for viability
|
| 1252 |
+
[:^^A::f:](3); // error: default argument provided by declarations from two scopes
|
| 1253 |
+
[:^^A::f:](); // OK, default arguments provided by declarations in the scope of A
|
| 1254 |
+
|
| 1255 |
+
using A::f;
|
| 1256 |
+
using B::f;
|
| 1257 |
+
f(3, 4); // OK, default argument was not used for viability
|
| 1258 |
+
f(3); // error: default argument provided by declaration from two scopes
|
| 1259 |
+
f(); // OK, default arguments provided by declarations in the scope of A
|
| 1260 |
+
|
| 1261 |
+
void g(int = 8);
|
| 1262 |
+
g(); // OK
|
| 1263 |
+
[:^^g:](); // error: host scope is block scope
|
| 1264 |
+
}
|
| 1265 |
+
|
| 1266 |
+
void h(int = 7);
|
| 1267 |
+
constexpr std::meta::info r = ^^h;
|
| 1268 |
+
void poison() {
|
| 1269 |
+
void h(int = 8);
|
| 1270 |
+
h(); // OK, calls h(8)
|
| 1271 |
+
[:^^h:](); // error: default argument provided by declarations from two scopes
|
| 1272 |
+
}
|
| 1273 |
+
void call_h() {
|
| 1274 |
+
[:^^h:](); // error: default argument provided by declarations from two scopes
|
| 1275 |
+
[:r:](); // error: default argument provided by declarations from two scopes
|
| 1276 |
+
}
|
| 1277 |
+
|
| 1278 |
+
template<typename... Ts>
|
| 1279 |
+
int k(int = 3, Ts...);
|
| 1280 |
+
int i = k<int>(); // error: no default argument for the second parameter
|
| 1281 |
+
int j = k<>(); // OK
|
| 1282 |
+
```
|
| 1283 |
+
|
| 1284 |
+
— *end example*]
|
| 1285 |
|
| 1286 |
Second, for a function to be viable, if it has associated constraints
|
| 1287 |
[[temp.constr.decl]], those constraints shall be satisfied
|
| 1288 |
[[temp.constr.constr]].
|
| 1289 |
|
|
|
|
| 1314 |
|
| 1315 |
- for some argument j, ICSʲ(`F₁`) is a better conversion sequence than
|
| 1316 |
ICSʲ(`F₂`), or, if not that,
|
| 1317 |
- the context is an initialization by user-defined conversion (see
|
| 1318 |
[[dcl.init]], [[over.match.conv]], and [[over.match.ref]]) and the
|
| 1319 |
+
standard conversion sequence from the result of `F₁` to the
|
| 1320 |
destination type (i.e., the type of the entity being initialized) is a
|
| 1321 |
better conversion sequence than the standard conversion sequence from
|
| 1322 |
+
the result of `F₂` to the destination type
|
| 1323 |
\[*Example 1*:
|
| 1324 |
``` cpp
|
| 1325 |
struct A {
|
| 1326 |
A();
|
| 1327 |
operator int();
|
|
|
|
| 1335 |
|
| 1336 |
— *end example*]
|
| 1337 |
or, if not that,
|
| 1338 |
- the context is an initialization by conversion function for direct
|
| 1339 |
reference binding [[over.match.ref]] of a reference to function type,
|
| 1340 |
+
the return type of `F₁` is the same kind of reference (lvalue or
|
| 1341 |
rvalue) as the reference being initialized, and the return type of
|
| 1342 |
+
`F₂` is not
|
| 1343 |
\[*Example 2*:
|
| 1344 |
``` cpp
|
| 1345 |
template <class T> struct A {
|
| 1346 |
operator T&(); // #1
|
| 1347 |
operator T&&(); // #2
|
|
|
|
| 1352 |
Fn&& rf = a; // calls #2
|
| 1353 |
```
|
| 1354 |
|
| 1355 |
— *end example*]
|
| 1356 |
or, if not that,
|
| 1357 |
+
- `F₁` is not a function template specialization and `F₂` is a function
|
| 1358 |
template specialization, or, if not that,
|
| 1359 |
+
- `F₁` and `F₂` are function template specializations, and the function
|
| 1360 |
+
template for `F₁` is more specialized than the template for `F₂`
|
| 1361 |
according to the partial ordering rules described in
|
| 1362 |
[[temp.func.order]], or, if not that,
|
| 1363 |
+
- `F₁` and `F₂` are non-template functions and `F₁` is more
|
| 1364 |
+
partial-ordering-constrained than `F₂` [[temp.constr.order]]
|
| 1365 |
+
\[*Example 3*:
|
| 1366 |
+
``` cpp
|
| 1367 |
+
template <typename T = int>
|
| 1368 |
+
struct S {
|
| 1369 |
+
constexpr void f(); // #1
|
| 1370 |
+
constexpr void f(this S&) requires true; // #2
|
| 1371 |
+
};
|
| 1372 |
+
|
| 1373 |
+
void test() {
|
| 1374 |
+
S<> s;
|
| 1375 |
+
s.f(); // calls #2
|
| 1376 |
+
}
|
| 1377 |
+
```
|
| 1378 |
+
|
| 1379 |
+
— *end example*]
|
| 1380 |
+
or, if not that,
|
| 1381 |
+
- `F₁` is a constructor for a class `D`, `F₂` is a constructor for a
|
| 1382 |
base class `B` of `D`, and for all arguments the corresponding
|
| 1383 |
+
parameters of `F₁` and `F₂` have the same type
|
| 1384 |
+
\[*Example 4*:
|
| 1385 |
``` cpp
|
| 1386 |
struct A {
|
| 1387 |
A(int = 0);
|
| 1388 |
};
|
| 1389 |
|
|
|
|
| 1397 |
}
|
| 1398 |
```
|
| 1399 |
|
| 1400 |
— *end example*]
|
| 1401 |
or, if not that,
|
| 1402 |
+
- `F₂` is a rewritten candidate [[over.match.oper]] and `F₁` is not
|
| 1403 |
+
\[*Example 5*:
|
| 1404 |
``` cpp
|
| 1405 |
struct S {
|
| 1406 |
friend auto operator<=>(const S&, const S&) = default; // #1
|
| 1407 |
friend bool operator<(const S&, const S&); // #2
|
| 1408 |
};
|
| 1409 |
bool b = S() < S(); // calls #2
|
| 1410 |
```
|
| 1411 |
|
| 1412 |
— *end example*]
|
| 1413 |
or, if not that,
|
| 1414 |
+
- `F₁` and `F₂` are rewritten candidates, and `F₂` is a synthesized
|
| 1415 |
+
candidate with reversed order of parameters and `F₁` is not
|
| 1416 |
+
\[*Example 6*:
|
| 1417 |
``` cpp
|
| 1418 |
struct S {
|
| 1419 |
friend std::weak_ordering operator<=>(const S&, int); // #1
|
| 1420 |
friend std::weak_ordering operator<=>(int, const S&); // #2
|
| 1421 |
};
|
| 1422 |
bool b = 1 < S(); // calls #2
|
| 1423 |
```
|
| 1424 |
|
| 1425 |
— *end example*]
|
| 1426 |
+
or, if not that,
|
| 1427 |
+
- `F₁` and `F₂` are generated from class template argument deduction
|
| 1428 |
+
[[over.match.class.deduct]] for a class `D`, and `F₂` is generated
|
| 1429 |
+
from inheriting constructors from a base class of `D` while `F₁` is
|
| 1430 |
not, and for each explicit function argument, the corresponding
|
| 1431 |
+
parameters of `F₁` and `F₂` are either both ellipses or have the same
|
| 1432 |
type, or, if not that,
|
| 1433 |
+
- `F₁` is generated from a *deduction-guide* [[over.match.class.deduct]]
|
| 1434 |
+
and `F₂` is not, or, if not that,
|
| 1435 |
+
- `F₁` is the copy deduction candidate [[over.match.class.deduct]] and
|
| 1436 |
+
`F₂` is not, or, if not that,
|
| 1437 |
+
- `F₁` is generated from a non-template constructor and `F₂` is
|
| 1438 |
generated from a constructor template.
|
| 1439 |
+
\[*Example 7*:
|
| 1440 |
``` cpp
|
| 1441 |
template <class T> struct A {
|
| 1442 |
using value_type = T;
|
| 1443 |
A(value_type); // #1
|
| 1444 |
A(const A&); // #2
|
|
|
|
| 1466 |
|
| 1467 |
If there is exactly one viable function that is a better function than
|
| 1468 |
all other viable functions, then it is the one selected by overload
|
| 1469 |
resolution; otherwise the call is ill-formed.[^7]
|
| 1470 |
|
| 1471 |
+
[*Example 8*:
|
| 1472 |
|
| 1473 |
``` cpp
|
| 1474 |
void Fcn(const int*, short);
|
| 1475 |
void Fcn(int*, int);
|
| 1476 |
|
|
|
|
| 1489 |
}
|
| 1490 |
```
|
| 1491 |
|
| 1492 |
— *end example*]
|
| 1493 |
|
| 1494 |
+
[*Note 1*: If the best viable function was made viable by one or more
|
| 1495 |
+
default arguments, additional requirements apply
|
| 1496 |
+
[[over.match.viable]]. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1497 |
|
| 1498 |
#### Implicit conversion sequences <a id="over.best.ics">[[over.best.ics]]</a>
|
| 1499 |
|
| 1500 |
##### General <a id="over.best.ics.general">[[over.best.ics.general]]</a>
|
| 1501 |
|
|
|
|
| 1508 |
|
| 1509 |
Implicit conversion sequences are concerned only with the type,
|
| 1510 |
cv-qualification, and value category of the argument and how these are
|
| 1511 |
converted to match the corresponding properties of the parameter.
|
| 1512 |
|
| 1513 |
+
[*Note 1*: Other properties, such as the lifetime, storage duration,
|
| 1514 |
+
linkage, alignment, accessibility of the argument, whether the argument
|
| 1515 |
+
is a bit-field, and whether a function is deleted
|
| 1516 |
+
[[dcl.fct.def.delete]], are ignored. So, although an implicit conversion
|
| 1517 |
+
sequence can be defined for a given argument-parameter pair, the
|
| 1518 |
+
conversion from the argument to the parameter might still be ill-formed
|
| 1519 |
+
in the final analysis. — *end note*]
|
| 1520 |
|
| 1521 |
A well-formed implicit conversion sequence is one of the following
|
| 1522 |
forms:
|
| 1523 |
|
| 1524 |
- a standard conversion sequence [[over.ics.scs]],
|
|
|
|
| 1575 |
[*Note 3*: When the parameter has a class type, this is a conceptual
|
| 1576 |
conversion defined for the purposes of [[over]]; the actual
|
| 1577 |
initialization is defined in terms of constructors and is not a
|
| 1578 |
conversion. — *end note*]
|
| 1579 |
|
| 1580 |
+
When the cv-unqualified version of the type of the argument expression
|
| 1581 |
+
is the same as the parameter type, the implicit conversion sequence is
|
| 1582 |
+
an identity conversion. When the parameter has a class type and the
|
| 1583 |
+
argument expression has a (possibly cv-qualified) derived class type,
|
| 1584 |
+
the implicit conversion sequence is a derived-to-base conversion from
|
| 1585 |
+
the derived class to the base class. A derived-to-base conversion has
|
| 1586 |
+
Conversion rank [[over.ics.scs]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1587 |
|
| 1588 |
[*Note 4*: There is no such standard conversion; this derived-to-base
|
| 1589 |
conversion exists only in the description of implicit conversion
|
| 1590 |
sequences. — *end note*]
|
| 1591 |
|
| 1592 |
+
[*Example 2*: An implicit conversion sequence from an argument of type
|
| 1593 |
+
`const A` to a parameter of type `A` can be formed, even if overload
|
| 1594 |
+
resolution for copy-initialization of `A` from the argument would not
|
| 1595 |
+
find a viable function [[over.match.ctor]], [[over.match.viable]]. The
|
| 1596 |
+
implicit conversion sequence for that case is the identity sequence; it
|
| 1597 |
+
contains no “conversion” from `const A` to `A`. — *end example*]
|
| 1598 |
+
|
| 1599 |
When the parameter is the implicit object parameter of a static member
|
| 1600 |
function, the implicit conversion sequence is a standard conversion
|
| 1601 |
sequence that is neither better nor worse than any other standard
|
| 1602 |
conversion sequence.
|
| 1603 |
|
| 1604 |
In all contexts, when converting to the implicit object parameter or
|
| 1605 |
when converting to the left operand of an assignment operation only
|
| 1606 |
standard conversion sequences are allowed.
|
| 1607 |
|
| 1608 |
+
[*Note 5*: When a conversion to the explicit object parameter occurs,
|
| 1609 |
+
it can include user-defined conversion sequences. — *end note*]
|
| 1610 |
|
| 1611 |
If no conversions are required to match an argument to a parameter type,
|
| 1612 |
the implicit conversion sequence is the standard conversion sequence
|
| 1613 |
consisting of the identity conversion [[over.ics.scs]].
|
| 1614 |
|
|
|
|
| 1715 |
when selecting the best user-defined conversion for a user-defined
|
| 1716 |
conversion sequence (see [[over.match.best]] and [[over.best.ics]]).
|
| 1717 |
|
| 1718 |
If the user-defined conversion is specified by a specialization of a
|
| 1719 |
conversion function template, the second standard conversion sequence
|
| 1720 |
+
shall have Exact Match rank.
|
| 1721 |
|
| 1722 |
A conversion of an expression of class type to the same class type is
|
| 1723 |
given Exact Match rank, and a conversion of an expression of class type
|
| 1724 |
to a base class of that type is given Conversion rank, in spite of the
|
| 1725 |
fact that a constructor (i.e., a user-defined conversion function) is
|
|
|
|
| 1731 |
call is matched with the ellipsis parameter specification of the
|
| 1732 |
function called (see [[expr.call]]).
|
| 1733 |
|
| 1734 |
##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
|
| 1735 |
|
| 1736 |
+
When a parameter of type “reference to cv `T`” binds directly
|
| 1737 |
+
[[dcl.init.ref]] to an argument expression:
|
| 1738 |
+
|
| 1739 |
+
- If the argument expression has a type that is a derived class of the
|
| 1740 |
+
parameter type, the implicit conversion sequence is a derived-to-base
|
| 1741 |
+
conversion [[over.best.ics]].
|
| 1742 |
+
- Otherwise, if the type of the argument is possibly cv-qualified `T`,
|
| 1743 |
+
or if `T` is an array type of unknown bound with element type `U` and
|
| 1744 |
+
the argument has an array type of known bound whose element type is
|
| 1745 |
+
possibly cv-qualified `U`, the implicit conversion sequence is the
|
| 1746 |
+
identity conversion.
|
| 1747 |
+
- Otherwise, if `T` is a function type, the implicit conversion sequence
|
| 1748 |
+
is a function pointer conversion.
|
| 1749 |
+
- Otherwise, the implicit conversion sequence is a qualification
|
| 1750 |
+
conversion.
|
| 1751 |
|
| 1752 |
[*Example 4*:
|
| 1753 |
|
| 1754 |
``` cpp
|
| 1755 |
struct A {};
|
| 1756 |
struct B : public A {} b;
|
| 1757 |
int f(A&);
|
| 1758 |
int f(B&);
|
| 1759 |
int i = f(b); // calls f(B&), an exact match, rather than f(A&), a conversion
|
| 1760 |
+
|
| 1761 |
+
void g() noexcept;
|
| 1762 |
+
int h(void (&)() noexcept); // #1
|
| 1763 |
+
int h(void (&)()); // #2
|
| 1764 |
+
int j = h(g); // calls #1, an exact match, rather than #2, a function pointer conversion
|
| 1765 |
```
|
| 1766 |
|
| 1767 |
— *end example*]
|
| 1768 |
|
| 1769 |
If the parameter binds directly to the result of applying a conversion
|
| 1770 |
function to the argument expression, the implicit conversion sequence is
|
| 1771 |
a user-defined conversion sequence [[over.ics.user]] whose second
|
| 1772 |
+
standard conversion sequence is determined by the above rules.
|
|
|
|
|
|
|
| 1773 |
|
| 1774 |
When a parameter of reference type is not bound directly to an argument
|
| 1775 |
expression, the conversion sequence is the one required to convert the
|
| 1776 |
argument expression to the referenced type according to
|
| 1777 |
[[over.best.ics]]. Conceptually, this conversion sequence corresponds to
|
|
|
|
| 1781 |
|
| 1782 |
Except for an implicit object parameter, for which see
|
| 1783 |
[[over.match.funcs]], an implicit conversion sequence cannot be formed
|
| 1784 |
if it requires binding an lvalue reference other than a reference to a
|
| 1785 |
non-volatile `const` type to an rvalue or binding an rvalue reference to
|
| 1786 |
+
an lvalue of object type.
|
| 1787 |
|
| 1788 |
[*Note 9*: This means, for example, that a candidate function cannot be
|
| 1789 |
a viable function if it has a non-`const` lvalue reference parameter
|
| 1790 |
(other than the implicit object parameter) and the corresponding
|
| 1791 |
argument would require a temporary to be created to initialize the
|
|
|
|
| 1808 |
|
| 1809 |
When an argument is an initializer list [[dcl.init.list]], it is not an
|
| 1810 |
expression and special rules apply for converting it to a parameter
|
| 1811 |
type.
|
| 1812 |
|
| 1813 |
+
If the initializer list is a *designated-initializer-list* and the
|
| 1814 |
+
parameter is not a reference, a conversion is only possible if the
|
| 1815 |
+
parameter has an aggregate type that can be initialized from the
|
| 1816 |
+
initializer list according to the rules for aggregate initialization
|
| 1817 |
+
[[dcl.init.aggr]], in which case the implicit conversion sequence is a
|
| 1818 |
+
user-defined conversion sequence whose second standard conversion
|
| 1819 |
+
sequence is an identity conversion.
|
| 1820 |
|
| 1821 |
[*Note 10*:
|
| 1822 |
|
| 1823 |
Aggregate initialization does not require that the members are declared
|
| 1824 |
in designation order. If, after overload resolution, the order does not
|
|
|
|
| 1874 |
f( {'a','b'} ); // OK, f(initializer_list<int>) integral promotion
|
| 1875 |
f( {1.0} ); // error: narrowing
|
| 1876 |
|
| 1877 |
struct A {
|
| 1878 |
A(std::initializer_list<double>); // #1
|
| 1879 |
+
A(std::initializer_list<std::complex<double>>); // #2
|
| 1880 |
A(std::initializer_list<std::string>); // #3
|
| 1881 |
};
|
| 1882 |
A a{ 1.0,2.0 }; // OK, uses #1
|
| 1883 |
|
| 1884 |
void g(A);
|
|
|
|
| 2122 |
```
|
| 2123 |
|
| 2124 |
— *end example*]
|
| 2125 |
or, if not that,
|
| 2126 |
- `S1` and `S2` include reference bindings [[dcl.init.ref]] and `S1`
|
| 2127 |
+
binds an lvalue reference to an lvalue of function type and `S2`
|
| 2128 |
+
binds an rvalue reference to an lvalue of function type
|
| 2129 |
\[*Example 4*:
|
| 2130 |
``` cpp
|
| 2131 |
int f(void(&)()); // #1
|
| 2132 |
int f(void(&&)()); // #2
|
| 2133 |
void g();
|
|
|
|
| 2135 |
```
|
| 2136 |
|
| 2137 |
— *end example*]
|
| 2138 |
or, if not that,
|
| 2139 |
- `S1` and `S2` differ only in their qualification conversion
|
| 2140 |
+
[[conv.qual]] and yield similar types `T1` and `T2`, respectively
|
| 2141 |
+
(where a standard conversion sequence that is a reference binding is
|
| 2142 |
+
considered to yield the cv-unqualified referenced type), where `T1`
|
| 2143 |
+
and `T2` are not the same type, and `const T2` is
|
| 2144 |
+
reference-compatible with `T1` [[dcl.init.ref]]
|
| 2145 |
\[*Example 5*:
|
| 2146 |
``` cpp
|
| 2147 |
int f(const volatile int *);
|
| 2148 |
int f(const int *);
|
| 2149 |
int i;
|
| 2150 |
int j = f(&i); // calls f(const int*)
|
| 2151 |
+
int g(const int*);
|
| 2152 |
+
int g(const volatile int* const&);
|
| 2153 |
+
int* p;
|
| 2154 |
+
int k = g(p); // calls g(const int*)
|
| 2155 |
```
|
| 2156 |
|
| 2157 |
— *end example*]
|
| 2158 |
or, if not that,
|
| 2159 |
- `S1`
|
| 2160 |
+
and `S2` bind “reference to `T1`” and “reference to `T2`”,
|
| 2161 |
+
respectively [[dcl.init.ref]], where `T1` and `T2` are not the same
|
| 2162 |
+
type, and `T2` is reference-compatible with `T1`
|
|
|
|
|
|
|
| 2163 |
\[*Example 6*:
|
| 2164 |
``` cpp
|
| 2165 |
int f(const int &);
|
| 2166 |
int f(int &);
|
| 2167 |
int g(const int &);
|
|
|
|
| 2177 |
};
|
| 2178 |
void g(const X& a, X b) {
|
| 2179 |
a.f(); // calls X::f() const
|
| 2180 |
b.f(); // calls X::f()
|
| 2181 |
}
|
| 2182 |
+
|
| 2183 |
+
int h(int (&)[]);
|
| 2184 |
+
int h(int (&)[1]);
|
| 2185 |
+
void g2() {
|
| 2186 |
+
int a[1];
|
| 2187 |
+
h(a); // calls h(int (&)[1])
|
| 2188 |
+
}
|
| 2189 |
+
```
|
| 2190 |
+
|
| 2191 |
+
— *end example*]
|
| 2192 |
+
or, if not that,
|
| 2193 |
+
- `S1` and `S2` bind the same reference type “reference to `T`” and
|
| 2194 |
+
have source types `V1` and `V2`, respectively, where the standard
|
| 2195 |
+
conversion sequence from `V1*` to `T*` is better than the standard
|
| 2196 |
+
conversion sequence from `V2*` to `T*`.
|
| 2197 |
+
\[*Example 7*:
|
| 2198 |
+
``` cpp
|
| 2199 |
+
struct Z {};
|
| 2200 |
+
|
| 2201 |
+
struct A {
|
| 2202 |
+
operator Z&();
|
| 2203 |
+
operator const Z&(); // #1
|
| 2204 |
+
};
|
| 2205 |
+
|
| 2206 |
+
struct B {
|
| 2207 |
+
operator Z();
|
| 2208 |
+
operator const Z&&(); // #2
|
| 2209 |
+
};
|
| 2210 |
+
|
| 2211 |
+
const Z& r1 = A(); // OK, uses #1
|
| 2212 |
+
const Z&& r2 = B(); // OK, uses #2
|
| 2213 |
```
|
| 2214 |
|
| 2215 |
— *end example*]
|
| 2216 |
- User-defined conversion sequence `U1` is a better conversion sequence
|
| 2217 |
than another user-defined conversion sequence `U2` if they contain the
|
| 2218 |
same user-defined conversion function or constructor or they
|
| 2219 |
initialize the same class in an aggregate initialization and in either
|
| 2220 |
case the second standard conversion sequence of `U1` is better than
|
| 2221 |
the second standard conversion sequence of `U2`.
|
| 2222 |
+
\[*Example 8*:
|
| 2223 |
``` cpp
|
| 2224 |
struct A {
|
| 2225 |
operator short();
|
| 2226 |
} a;
|
| 2227 |
int f(int);
|
|
|
|
| 2249 |
to the rank of `FP2`, and
|
| 2250 |
- `T3` is not a floating-point type, or `T3` is a floating-point type
|
| 2251 |
whose rank is not equal to the rank of `FP1`, or the floating-point
|
| 2252 |
conversion subrank [[conv.rank]] of `FP2` is greater than the
|
| 2253 |
subrank of `T3`.
|
| 2254 |
+
\[*Example 9*:
|
| 2255 |
``` cpp
|
| 2256 |
int f(std::float32_t);
|
| 2257 |
int f(std::float64_t);
|
| 2258 |
int f(long long);
|
| 2259 |
float x;
|
|
|
|
| 2270 |
of `B*` to `void*`.
|
| 2271 |
- If class `B` is derived directly or indirectly from class `A` and
|
| 2272 |
class `C` is derived directly or indirectly from `B`,
|
| 2273 |
- conversion of `C*` to `B*` is better than conversion of `C*` to
|
| 2274 |
`A*`,
|
| 2275 |
+
\[*Example 10*:
|
| 2276 |
``` cpp
|
| 2277 |
struct A {};
|
| 2278 |
struct B : public A {};
|
| 2279 |
struct C : public B {};
|
| 2280 |
C* pc;
|