- tmp/tmpzy6drflg/{from.md → to.md} +400 -242
tmp/tmpzy6drflg/{from.md → to.md}
RENAMED
|
@@ -4,17 +4,21 @@
|
|
| 4 |
|
| 5 |
[*Note 1*: Each of two or more entities with the same name in the same
|
| 6 |
scope, which must be functions or function templates, is commonly called
|
| 7 |
an “overload”. — *end note*]
|
| 8 |
|
| 9 |
-
When a function is
|
| 10 |
-
referenced and the validity of the call are determined by
|
| 11 |
-
types of the arguments at the point of use with the types
|
| 12 |
-
parameters in the declarations in the overload set. This function
|
| 13 |
selection process is called *overload resolution* and is defined in
|
| 14 |
[[over.match]].
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
[*Example 1*:
|
| 17 |
|
| 18 |
``` cpp
|
| 19 |
double abs(double);
|
| 20 |
int abs(int);
|
|
@@ -121,12 +125,12 @@ parameter is
|
|
| 121 |
- “lvalue reference to cv `X`” for functions declared without a
|
| 122 |
*ref-qualifier* or with the `&` *ref-qualifier*
|
| 123 |
- “rvalue reference to cv `X`” for functions declared with the `&&`
|
| 124 |
*ref-qualifier*
|
| 125 |
|
| 126 |
-
where `X` is the class of which the function is a member and cv
|
| 127 |
-
cv-qualification on the member function declaration.
|
| 128 |
|
| 129 |
[*Example 1*: For a `const` member function of class `X`, the extra
|
| 130 |
parameter is assumed to have type “lvalue reference to
|
| 131 |
`const X`”. — *end example*]
|
| 132 |
|
|
@@ -278,63 +282,80 @@ If the function selected by overload resolution is an implicit object
|
|
| 278 |
member function, the program is ill-formed.
|
| 279 |
|
| 280 |
[*Note 2*: The resolution of the address of an overload set in other
|
| 281 |
contexts is described in [[over.over]]. — *end note*]
|
| 282 |
|
| 283 |
-
##### Call to
|
| 284 |
|
| 285 |
Of interest in [[over.call.func]] are only those function calls in
|
| 286 |
-
which the *postfix-expression* ultimately contains an *id-expression*
|
| 287 |
-
that
|
| 288 |
-
nested arbitrarily deep in parentheses,
|
|
|
|
| 289 |
|
| 290 |
``` bnf
|
| 291 |
postfix-expression:
|
| 292 |
postfix-expression '.' id-expression
|
|
|
|
| 293 |
postfix-expression '->' id-expression
|
| 294 |
-
|
|
|
|
|
|
|
| 295 |
```
|
| 296 |
|
| 297 |
These represent two syntactic subcategories of function calls: qualified
|
| 298 |
function calls and unqualified function calls.
|
| 299 |
|
| 300 |
-
In qualified function calls, the function is
|
| 301 |
-
preceded by an `->` or `.`
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
[[over]] assumes that the
|
| 306 |
-
|
|
|
|
| 307 |
|
| 308 |
-
The
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
the
|
|
|
|
|
|
|
| 313 |
|
| 314 |
-
In unqualified function calls, the function is
|
| 315 |
-
*
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
*
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
|
| 328 |
-
if
|
| 329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
|
| 331 |
[*Example 1*:
|
| 332 |
|
| 333 |
``` cpp
|
| 334 |
struct C {
|
| 335 |
-
|
| 336 |
void b() {
|
| 337 |
a(); // OK, (*this).a()
|
| 338 |
}
|
| 339 |
|
| 340 |
void c(this const C&); // #1
|
|
@@ -367,10 +388,19 @@ void d() {
|
|
| 367 |
void k(this int);
|
| 368 |
operator int() const;
|
| 369 |
void m(this const C& c) {
|
| 370 |
c.k(); // OK
|
| 371 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
};
|
| 373 |
```
|
| 374 |
|
| 375 |
— *end example*]
|
| 376 |
|
|
@@ -397,11 +427,11 @@ returning `R`”, or the type “reference to function of (`P₁`, …, `Pₙ`)
|
|
| 397 |
returning `R`”, a *surrogate call function* with the unique name
|
| 398 |
*call-function* and having the form
|
| 399 |
|
| 400 |
``` bnf
|
| 401 |
'R' *call-function* '(' conversion-type-id \ %
|
| 402 |
-
'F, P₁ a₁, …, Pₙ aₙ)' '{ return F (a₁, …, aₙ); }'
|
| 403 |
```
|
| 404 |
|
| 405 |
is also considered as a candidate function. Similarly, surrogate call
|
| 406 |
functions are added to the set of candidate functions for each
|
| 407 |
non-explicit conversion function declared in a base class of `T`
|
|
@@ -480,14 +510,14 @@ However, the operands are sequenced in the order prescribed for the
|
|
| 480 |
built-in operator [[expr.compound]].
|
| 481 |
|
| 482 |
**Table: Relationship between operator and function call notation** <a id="over.match.oper">[over.match.oper]</a>
|
| 483 |
|
| 484 |
| Subclause | Expression | As member function | As non-member function |
|
| 485 |
-
| ------------ | ---------- | ------------------- | ---------------------- |
|
| 486 |
| (a)} |
|
| 487 |
| (a, b)} |
|
| 488 |
-
| [[over.
|
| 489 |
| [[over.sub]] | `a[b]` | `(a).operator[](b)` | |
|
| 490 |
| [[over.ref]] | `a->` | `(a).operator->( )` | |
|
| 491 |
| (a, 0)} |
|
| 492 |
|
| 493 |
|
|
@@ -584,16 +614,12 @@ inline namespace N {
|
|
| 584 |
bool d1 = 0 == D(); // OK, calls reversed #4; #5 does not forbid #4 as a rewrite target
|
| 585 |
```
|
| 586 |
|
| 587 |
— *end example*]
|
| 588 |
|
| 589 |
-
For the built-in assignment operators,
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
- no temporaries are introduced to hold the left operand, and
|
| 593 |
-
- no user-defined conversions are applied to the left operand to achieve
|
| 594 |
-
a type match with the left-most parameter of a built-in candidate.
|
| 595 |
|
| 596 |
For all other operators, no such restrictions apply.
|
| 597 |
|
| 598 |
The set of candidate functions for overload resolution for some operator
|
| 599 |
`@` is the union of the member candidates, the non-member candidates,
|
|
@@ -702,17 +728,18 @@ void B::f() {
|
|
| 702 |
|
| 703 |
When objects of class type are direct-initialized [[dcl.init]],
|
| 704 |
copy-initialized from an expression of the same or a derived class type
|
| 705 |
[[dcl.init]], or default-initialized [[dcl.init]], overload resolution
|
| 706 |
selects the constructor. For direct-initialization or
|
| 707 |
-
default-initialization
|
| 708 |
-
copy-initialization, the candidate functions are all the
|
| 709 |
-
the class of the object being initialized.
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
|
|
|
| 714 |
|
| 715 |
#### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
|
| 716 |
|
| 717 |
Under the conditions specified in [[dcl.init]], as part of a
|
| 718 |
copy-initialization of an object of class type, a user-defined
|
|
@@ -725,11 +752,11 @@ to a possibly cv-qualified class type is determined in terms of a
|
|
| 725 |
corresponding non-reference copy-initialization. — *end note*]
|
| 726 |
|
| 727 |
Assuming that “*cv1* `T`” is the type of the object being initialized,
|
| 728 |
with `T` a class type, the candidate functions are selected as follows:
|
| 729 |
|
| 730 |
-
- The
|
| 731 |
functions.
|
| 732 |
- When the type of the initializer expression is a class type “cv `S`”,
|
| 733 |
conversion functions are considered. The permissible types for
|
| 734 |
non-explicit conversion functions are `T` and any class derived from
|
| 735 |
`T`. When initializing a temporary object [[class.mem]] to be bound to
|
|
@@ -776,14 +803,13 @@ initializer expression. Overload resolution is used to select the
|
|
| 776 |
conversion function to be invoked. Assuming that “reference to *cv1*
|
| 777 |
`T`” is the type of the reference being initialized, the candidate
|
| 778 |
functions are selected as follows:
|
| 779 |
|
| 780 |
- Let R be a set of types including
|
| 781 |
-
- “lvalue reference to *cv2* `T2`” (when
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
an rvalue reference or an lvalue reference to function)
|
| 785 |
|
| 786 |
for any `T2`. The permissible types for non-explicit conversion
|
| 787 |
functions are the members of R where “*cv1* `T`” is
|
| 788 |
reference-compatible [[dcl.init.ref]] with “*cv2* `T2`”. For
|
| 789 |
direct-initialization, the permissible types for explicit conversion
|
|
@@ -816,40 +842,47 @@ resolution selects the constructor in two phases:
|
|
| 816 |
|
| 817 |
In copy-list-initialization, if an explicit constructor is chosen, the
|
| 818 |
initialization is ill-formed.
|
| 819 |
|
| 820 |
[*Note 1*: This differs from other situations
|
| 821 |
-
[[over.match.ctor]], [[over.match.copy]], where only
|
| 822 |
constructors are considered for copy-initialization. This restriction
|
| 823 |
only applies if this initialization is part of the final result of
|
| 824 |
overload resolution. — *end note*]
|
| 825 |
|
| 826 |
#### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
|
| 827 |
|
| 828 |
When resolving a placeholder for a deduced class type
|
| 829 |
-
[[dcl.type.class.deduct]] where the *template-name*
|
| 830 |
-
class template `C`, a set
|
| 831 |
-
the guides of `C`, is formed
|
|
|
|
| 832 |
|
| 833 |
- If `C` is defined, for each constructor of `C`, a function template
|
| 834 |
with the following properties:
|
| 835 |
- The template parameters are the template parameters of `C` followed
|
| 836 |
by the template parameters (including default template arguments) of
|
| 837 |
the constructor, if any.
|
| 838 |
-
- The
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 839 |
- The return type is the class template specialization designated by
|
| 840 |
`C` and template arguments corresponding to the template parameters
|
| 841 |
of `C`.
|
| 842 |
- If `C` is not defined or does not declare any constructors, an
|
| 843 |
additional function template derived as above from a hypothetical
|
| 844 |
constructor `C()`.
|
| 845 |
- An additional function template derived as above from a hypothetical
|
| 846 |
constructor `C(C)`, called the *copy deduction candidate*.
|
| 847 |
- For each *deduction-guide*, a function or function template with the
|
| 848 |
following properties:
|
| 849 |
-
- The template
|
| 850 |
-
of the *deduction-guide*.
|
| 851 |
- The return type is the *simple-template-id* of the
|
| 852 |
*deduction-guide*.
|
| 853 |
|
| 854 |
In addition, if `C` is defined and its definition satisfies the
|
| 855 |
conditions for an aggregate class [[dcl.init.aggr]] with the assumption
|
|
@@ -909,11 +942,11 @@ specialization whose template parameter list is that of `A` and whose
|
|
| 909 |
template argument list is a specialization of `A` with the template
|
| 910 |
argument list of `A` [[temp.dep.type]] having a member typedef `type`
|
| 911 |
designating a template specialization with the template argument list of
|
| 912 |
`A` but with `C` as the template.
|
| 913 |
|
| 914 |
-
[*Note
|
| 915 |
specialization is that of `C`, the template argument list of the
|
| 916 |
specialization is `B`, and the member typedef names `C` with the
|
| 917 |
template argument list of `C`. — *end note*]
|
| 918 |
|
| 919 |
[*Example 1*:
|
|
@@ -966,12 +999,13 @@ J j = { "ghi" }; // error: cannot bind reference to array of unsigned char to
|
|
| 966 |
```
|
| 967 |
|
| 968 |
— *end example*]
|
| 969 |
|
| 970 |
When resolving a placeholder for a deduced class type
|
| 971 |
-
[[dcl.type.simple]] where the *template-name*
|
| 972 |
-
`A`, the *defining-type-id* of `A` must be
|
|
|
|
| 973 |
|
| 974 |
``` bnf
|
| 975 |
typenameₒₚₜ nested-name-specifierₒₚₜ templateₒₚₜ simple-template-id
|
| 976 |
```
|
| 977 |
|
|
@@ -1211,15 +1245,76 @@ parameters to agree in number with the arguments in the list.
|
|
| 1211 |
- A candidate function having fewer than m parameters is viable only if
|
| 1212 |
it has an ellipsis in its parameter list [[dcl.fct]]. For the purposes
|
| 1213 |
of overload resolution, any argument for which there is no
|
| 1214 |
corresponding parameter is considered to “match the ellipsis”
|
| 1215 |
[[over.ics.ellipsis]].
|
| 1216 |
-
- A candidate function having more than m parameters is viable only
|
| 1217 |
-
|
| 1218 |
-
|
| 1219 |
-
|
| 1220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1221 |
|
| 1222 |
Second, for a function to be viable, if it has associated constraints
|
| 1223 |
[[temp.constr.decl]], those constraints shall be satisfied
|
| 1224 |
[[temp.constr.constr]].
|
| 1225 |
|
|
@@ -1250,14 +1345,14 @@ then
|
|
| 1250 |
|
| 1251 |
- for some argument j, ICSʲ(`F₁`) is a better conversion sequence than
|
| 1252 |
ICSʲ(`F₂`), or, if not that,
|
| 1253 |
- the context is an initialization by user-defined conversion (see
|
| 1254 |
[[dcl.init]], [[over.match.conv]], and [[over.match.ref]]) and the
|
| 1255 |
-
standard conversion sequence from the
|
| 1256 |
destination type (i.e., the type of the entity being initialized) is a
|
| 1257 |
better conversion sequence than the standard conversion sequence from
|
| 1258 |
-
the
|
| 1259 |
\[*Example 1*:
|
| 1260 |
``` cpp
|
| 1261 |
struct A {
|
| 1262 |
A();
|
| 1263 |
operator int();
|
|
@@ -1271,13 +1366,13 @@ then
|
|
| 1271 |
|
| 1272 |
— *end example*]
|
| 1273 |
or, if not that,
|
| 1274 |
- the context is an initialization by conversion function for direct
|
| 1275 |
reference binding [[over.match.ref]] of a reference to function type,
|
| 1276 |
-
the return type of `
|
| 1277 |
rvalue) as the reference being initialized, and the return type of
|
| 1278 |
-
`
|
| 1279 |
\[*Example 2*:
|
| 1280 |
``` cpp
|
| 1281 |
template <class T> struct A {
|
| 1282 |
operator T&(); // #1
|
| 1283 |
operator T&&(); // #2
|
|
@@ -1288,24 +1383,38 @@ then
|
|
| 1288 |
Fn&& rf = a; // calls #2
|
| 1289 |
```
|
| 1290 |
|
| 1291 |
— *end example*]
|
| 1292 |
or, if not that,
|
| 1293 |
-
- `
|
| 1294 |
template specialization, or, if not that,
|
| 1295 |
-
- `
|
| 1296 |
-
template for `
|
| 1297 |
according to the partial ordering rules described in
|
| 1298 |
[[temp.func.order]], or, if not that,
|
| 1299 |
-
- `
|
| 1300 |
-
|
| 1301 |
-
|
| 1302 |
-
|
| 1303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1304 |
base class `B` of `D`, and for all arguments the corresponding
|
| 1305 |
-
parameters of `
|
| 1306 |
-
\[*Example
|
| 1307 |
``` cpp
|
| 1308 |
struct A {
|
| 1309 |
A(int = 0);
|
| 1310 |
};
|
| 1311 |
|
|
@@ -1319,48 +1428,48 @@ then
|
|
| 1319 |
}
|
| 1320 |
```
|
| 1321 |
|
| 1322 |
— *end example*]
|
| 1323 |
or, if not that,
|
| 1324 |
-
- `
|
| 1325 |
-
\[*Example
|
| 1326 |
``` cpp
|
| 1327 |
struct S {
|
| 1328 |
friend auto operator<=>(const S&, const S&) = default; // #1
|
| 1329 |
friend bool operator<(const S&, const S&); // #2
|
| 1330 |
};
|
| 1331 |
bool b = S() < S(); // calls #2
|
| 1332 |
```
|
| 1333 |
|
| 1334 |
— *end example*]
|
| 1335 |
or, if not that,
|
| 1336 |
-
- `
|
| 1337 |
-
candidate with reversed order of parameters and `
|
| 1338 |
-
\[*Example
|
| 1339 |
``` cpp
|
| 1340 |
struct S {
|
| 1341 |
friend std::weak_ordering operator<=>(const S&, int); // #1
|
| 1342 |
friend std::weak_ordering operator<=>(int, const S&); // #2
|
| 1343 |
};
|
| 1344 |
bool b = 1 < S(); // calls #2
|
| 1345 |
```
|
| 1346 |
|
| 1347 |
— *end example*]
|
| 1348 |
-
or, if not that
|
| 1349 |
-
- `
|
| 1350 |
-
[[over.match.class.deduct]] for a class `D`, and `
|
| 1351 |
-
from inheriting constructors from a base class of `D` while `
|
| 1352 |
not, and for each explicit function argument, the corresponding
|
| 1353 |
-
parameters of `
|
| 1354 |
type, or, if not that,
|
| 1355 |
-
- `
|
| 1356 |
-
and `
|
| 1357 |
-
- `
|
| 1358 |
-
`
|
| 1359 |
-
- `
|
| 1360 |
generated from a constructor template.
|
| 1361 |
-
\[*Example
|
| 1362 |
``` cpp
|
| 1363 |
template <class T> struct A {
|
| 1364 |
using value_type = T;
|
| 1365 |
A(value_type); // #1
|
| 1366 |
A(const A&); // #2
|
|
@@ -1388,11 +1497,11 @@ then
|
|
| 1388 |
|
| 1389 |
If there is exactly one viable function that is a better function than
|
| 1390 |
all other viable functions, then it is the one selected by overload
|
| 1391 |
resolution; otherwise the call is ill-formed.[^7]
|
| 1392 |
|
| 1393 |
-
[*Example
|
| 1394 |
|
| 1395 |
``` cpp
|
| 1396 |
void Fcn(const int*, short);
|
| 1397 |
void Fcn(int*, int);
|
| 1398 |
|
|
@@ -1411,35 +1520,13 @@ void f() {
|
|
| 1411 |
}
|
| 1412 |
```
|
| 1413 |
|
| 1414 |
— *end example*]
|
| 1415 |
|
| 1416 |
-
If the best viable function
|
| 1417 |
-
|
| 1418 |
-
|
| 1419 |
-
viable, the program is ill-formed.
|
| 1420 |
-
|
| 1421 |
-
[*Example 8*:
|
| 1422 |
-
|
| 1423 |
-
``` cpp
|
| 1424 |
-
namespace A {
|
| 1425 |
-
extern "C" void f(int = 5);
|
| 1426 |
-
}
|
| 1427 |
-
namespace B {
|
| 1428 |
-
extern "C" void f(int = 5);
|
| 1429 |
-
}
|
| 1430 |
-
|
| 1431 |
-
using A::f;
|
| 1432 |
-
using B::f;
|
| 1433 |
-
|
| 1434 |
-
void use() {
|
| 1435 |
-
f(3); // OK, default argument was not used for viability
|
| 1436 |
-
f(); // error: found default argument twice
|
| 1437 |
-
}
|
| 1438 |
-
```
|
| 1439 |
-
|
| 1440 |
-
— *end example*]
|
| 1441 |
|
| 1442 |
#### Implicit conversion sequences <a id="over.best.ics">[[over.best.ics]]</a>
|
| 1443 |
|
| 1444 |
##### General <a id="over.best.ics.general">[[over.best.ics.general]]</a>
|
| 1445 |
|
|
@@ -1452,17 +1539,17 @@ single expression [[dcl.init]], [[dcl.init.ref]].
|
|
| 1452 |
|
| 1453 |
Implicit conversion sequences are concerned only with the type,
|
| 1454 |
cv-qualification, and value category of the argument and how these are
|
| 1455 |
converted to match the corresponding properties of the parameter.
|
| 1456 |
|
| 1457 |
-
[*Note 1*: Other properties, such as the lifetime, storage
|
| 1458 |
-
alignment, accessibility of the argument, whether the argument
|
| 1459 |
-
bit-field, and whether a function is deleted
|
| 1460 |
-
ignored. So, although an implicit conversion
|
| 1461 |
-
a given argument-parameter pair, the
|
| 1462 |
-
parameter might still be ill-formed
|
| 1463 |
-
analysis. — *end note*]
|
| 1464 |
|
| 1465 |
A well-formed implicit conversion sequence is one of the following
|
| 1466 |
forms:
|
| 1467 |
|
| 1468 |
- a standard conversion sequence [[over.ics.scs]],
|
|
@@ -1519,40 +1606,40 @@ parameter.
|
|
| 1519 |
[*Note 3*: When the parameter has a class type, this is a conceptual
|
| 1520 |
conversion defined for the purposes of [[over]]; the actual
|
| 1521 |
initialization is defined in terms of constructors and is not a
|
| 1522 |
conversion. — *end note*]
|
| 1523 |
|
| 1524 |
-
|
| 1525 |
-
|
| 1526 |
-
|
| 1527 |
-
|
| 1528 |
-
|
| 1529 |
-
|
| 1530 |
-
|
| 1531 |
-
|
| 1532 |
-
When the parameter has a class type and the argument expression has the
|
| 1533 |
-
same type, the implicit conversion sequence is an identity conversion.
|
| 1534 |
-
When the parameter has a class type and the argument expression has a
|
| 1535 |
-
derived class type, the implicit conversion sequence is a
|
| 1536 |
-
derived-to-base conversion from the derived class to the base class. A
|
| 1537 |
-
derived-to-base conversion has Conversion rank [[over.ics.scs]].
|
| 1538 |
|
| 1539 |
[*Note 4*: There is no such standard conversion; this derived-to-base
|
| 1540 |
conversion exists only in the description of implicit conversion
|
| 1541 |
sequences. — *end note*]
|
| 1542 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1543 |
When the parameter is the implicit object parameter of a static member
|
| 1544 |
function, the implicit conversion sequence is a standard conversion
|
| 1545 |
sequence that is neither better nor worse than any other standard
|
| 1546 |
conversion sequence.
|
| 1547 |
|
| 1548 |
In all contexts, when converting to the implicit object parameter or
|
| 1549 |
when converting to the left operand of an assignment operation only
|
| 1550 |
standard conversion sequences are allowed.
|
| 1551 |
|
| 1552 |
-
[*Note 5*: When
|
| 1553 |
-
user-defined conversion sequences
|
| 1554 |
|
| 1555 |
If no conversions are required to match an argument to a parameter type,
|
| 1556 |
the implicit conversion sequence is the standard conversion sequence
|
| 1557 |
consisting of the identity conversion [[over.ics.scs]].
|
| 1558 |
|
|
@@ -1659,11 +1746,11 @@ the special rules for initialization by user-defined conversion apply
|
|
| 1659 |
when selecting the best user-defined conversion for a user-defined
|
| 1660 |
conversion sequence (see [[over.match.best]] and [[over.best.ics]]).
|
| 1661 |
|
| 1662 |
If the user-defined conversion is specified by a specialization of a
|
| 1663 |
conversion function template, the second standard conversion sequence
|
| 1664 |
-
shall have
|
| 1665 |
|
| 1666 |
A conversion of an expression of class type to the same class type is
|
| 1667 |
given Exact Match rank, and a conversion of an expression of class type
|
| 1668 |
to a base class of that type is given Conversion rank, in spite of the
|
| 1669 |
fact that a constructor (i.e., a user-defined conversion function) is
|
|
@@ -1675,34 +1762,47 @@ An ellipsis conversion sequence occurs when an argument in a function
|
|
| 1675 |
call is matched with the ellipsis parameter specification of the
|
| 1676 |
function called (see [[expr.call]]).
|
| 1677 |
|
| 1678 |
##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
|
| 1679 |
|
| 1680 |
-
When a parameter of
|
| 1681 |
-
|
| 1682 |
-
|
| 1683 |
-
|
| 1684 |
-
sequence is a derived-to-base
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1685 |
|
| 1686 |
[*Example 4*:
|
| 1687 |
|
| 1688 |
``` cpp
|
| 1689 |
struct A {};
|
| 1690 |
struct B : public A {} b;
|
| 1691 |
int f(A&);
|
| 1692 |
int f(B&);
|
| 1693 |
int i = f(b); // calls f(B&), an exact match, rather than f(A&), a conversion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1694 |
```
|
| 1695 |
|
| 1696 |
— *end example*]
|
| 1697 |
|
| 1698 |
If the parameter binds directly to the result of applying a conversion
|
| 1699 |
function to the argument expression, the implicit conversion sequence is
|
| 1700 |
a user-defined conversion sequence [[over.ics.user]] whose second
|
| 1701 |
-
standard conversion sequence is
|
| 1702 |
-
conversion function returns an entity of a type that is a derived class
|
| 1703 |
-
of the parameter type, a derived-to-base conversion.
|
| 1704 |
|
| 1705 |
When a parameter of reference type is not bound directly to an argument
|
| 1706 |
expression, the conversion sequence is the one required to convert the
|
| 1707 |
argument expression to the referenced type according to
|
| 1708 |
[[over.best.ics]]. Conceptually, this conversion sequence corresponds to
|
|
@@ -1712,11 +1812,11 @@ the initialization itself and does not constitute a conversion.
|
|
| 1712 |
|
| 1713 |
Except for an implicit object parameter, for which see
|
| 1714 |
[[over.match.funcs]], an implicit conversion sequence cannot be formed
|
| 1715 |
if it requires binding an lvalue reference other than a reference to a
|
| 1716 |
non-volatile `const` type to an rvalue or binding an rvalue reference to
|
| 1717 |
-
an lvalue
|
| 1718 |
|
| 1719 |
[*Note 9*: This means, for example, that a candidate function cannot be
|
| 1720 |
a viable function if it has a non-`const` lvalue reference parameter
|
| 1721 |
(other than the implicit object parameter) and the corresponding
|
| 1722 |
argument would require a temporary to be created to initialize the
|
|
@@ -1739,16 +1839,17 @@ non-`const` lvalue reference to a bit-field
|
|
| 1739 |
|
| 1740 |
When an argument is an initializer list [[dcl.init.list]], it is not an
|
| 1741 |
expression and special rules apply for converting it to a parameter
|
| 1742 |
type.
|
| 1743 |
|
| 1744 |
-
If the initializer list is a *designated-initializer-list*
|
| 1745 |
-
is
|
| 1746 |
-
|
| 1747 |
-
|
| 1748 |
-
|
| 1749 |
-
|
|
|
|
| 1750 |
|
| 1751 |
[*Note 10*:
|
| 1752 |
|
| 1753 |
Aggregate initialization does not require that the members are declared
|
| 1754 |
in designation order. If, after overload resolution, the order does not
|
|
@@ -1804,11 +1905,11 @@ f( {1,2,3} ); // OK, f(initializer_list<int>) identity convers
|
|
| 1804 |
f( {'a','b'} ); // OK, f(initializer_list<int>) integral promotion
|
| 1805 |
f( {1.0} ); // error: narrowing
|
| 1806 |
|
| 1807 |
struct A {
|
| 1808 |
A(std::initializer_list<double>); // #1
|
| 1809 |
-
A(std::initializer_list<complex<double>>);
|
| 1810 |
A(std::initializer_list<std::string>); // #3
|
| 1811 |
};
|
| 1812 |
A a{ 1.0,2.0 }; // OK, uses #1
|
| 1813 |
|
| 1814 |
void g(A);
|
|
@@ -2052,12 +2153,12 @@ conversion sequences unless one of the following rules applies:
|
|
| 2052 |
```
|
| 2053 |
|
| 2054 |
— *end example*]
|
| 2055 |
or, if not that,
|
| 2056 |
- `S1` and `S2` include reference bindings [[dcl.init.ref]] and `S1`
|
| 2057 |
-
binds an lvalue reference to
|
| 2058 |
-
rvalue reference to
|
| 2059 |
\[*Example 4*:
|
| 2060 |
``` cpp
|
| 2061 |
int f(void(&)()); // #1
|
| 2062 |
int f(void(&&)()); // #2
|
| 2063 |
void g();
|
|
@@ -2065,28 +2166,33 @@ conversion sequences unless one of the following rules applies:
|
|
| 2065 |
```
|
| 2066 |
|
| 2067 |
— *end example*]
|
| 2068 |
or, if not that,
|
| 2069 |
- `S1` and `S2` differ only in their qualification conversion
|
| 2070 |
-
[[conv.qual]] and yield similar types `T1` and `T2`, respectively
|
| 2071 |
-
where
|
|
|
|
|
|
|
|
|
|
| 2072 |
\[*Example 5*:
|
| 2073 |
``` cpp
|
| 2074 |
int f(const volatile int *);
|
| 2075 |
int f(const int *);
|
| 2076 |
int i;
|
| 2077 |
int j = f(&i); // calls f(const int*)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2078 |
```
|
| 2079 |
|
| 2080 |
— *end example*]
|
| 2081 |
or, if not that,
|
| 2082 |
- `S1`
|
| 2083 |
-
and `S2`
|
| 2084 |
-
|
| 2085 |
-
|
| 2086 |
-
`S2` refers is more cv-qualified than the type to which the
|
| 2087 |
-
reference initialized by `S1` refers.
|
| 2088 |
\[*Example 6*:
|
| 2089 |
``` cpp
|
| 2090 |
int f(const int &);
|
| 2091 |
int f(int &);
|
| 2092 |
int g(const int &);
|
|
@@ -2102,20 +2208,51 @@ conversion sequences unless one of the following rules applies:
|
|
| 2102 |
};
|
| 2103 |
void g(const X& a, X b) {
|
| 2104 |
a.f(); // calls X::f() const
|
| 2105 |
b.f(); // calls X::f()
|
| 2106 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2107 |
```
|
| 2108 |
|
| 2109 |
— *end example*]
|
| 2110 |
- User-defined conversion sequence `U1` is a better conversion sequence
|
| 2111 |
than another user-defined conversion sequence `U2` if they contain the
|
| 2112 |
same user-defined conversion function or constructor or they
|
| 2113 |
initialize the same class in an aggregate initialization and in either
|
| 2114 |
case the second standard conversion sequence of `U1` is better than
|
| 2115 |
the second standard conversion sequence of `U2`.
|
| 2116 |
-
\[*Example
|
| 2117 |
``` cpp
|
| 2118 |
struct A {
|
| 2119 |
operator short();
|
| 2120 |
} a;
|
| 2121 |
int f(int);
|
|
@@ -2143,11 +2280,11 @@ indistinguishable unless one of the following rules applies:
|
|
| 2143 |
to the rank of `FP2`, and
|
| 2144 |
- `T3` is not a floating-point type, or `T3` is a floating-point type
|
| 2145 |
whose rank is not equal to the rank of `FP1`, or the floating-point
|
| 2146 |
conversion subrank [[conv.rank]] of `FP2` is greater than the
|
| 2147 |
subrank of `T3`.
|
| 2148 |
-
\[*Example
|
| 2149 |
``` cpp
|
| 2150 |
int f(std::float32_t);
|
| 2151 |
int f(std::float64_t);
|
| 2152 |
int f(long long);
|
| 2153 |
float x;
|
|
@@ -2164,11 +2301,11 @@ indistinguishable unless one of the following rules applies:
|
|
| 2164 |
of `B*` to `void*`.
|
| 2165 |
- If class `B` is derived directly or indirectly from class `A` and
|
| 2166 |
class `C` is derived directly or indirectly from `B`,
|
| 2167 |
- conversion of `C*` to `B*` is better than conversion of `C*` to
|
| 2168 |
`A*`,
|
| 2169 |
-
\[*Example
|
| 2170 |
``` cpp
|
| 2171 |
struct A {};
|
| 2172 |
struct B : public A {};
|
| 2173 |
struct C : public B {};
|
| 2174 |
C* pc;
|
|
@@ -2199,29 +2336,31 @@ indistinguishable unless one of the following rules applies:
|
|
| 2199 |
[[over.match.best]]); in all other contexts, the source types will be
|
| 2200 |
the same and the target types will be different. — *end note*]
|
| 2201 |
|
| 2202 |
## Address of an overload set <a id="over.over">[[over.over]]</a>
|
| 2203 |
|
| 2204 |
-
An
|
| 2205 |
-
|
| 2206 |
-
|
| 2207 |
-
|
| 2208 |
-
|
| 2209 |
-
The target can be
|
| 2210 |
|
| 2211 |
- an object or reference being initialized
|
| 2212 |
[[dcl.init]], [[dcl.init.ref]], [[dcl.init.list]],
|
| 2213 |
-
- the left side of an assignment [[expr.
|
| 2214 |
- a parameter of a function [[expr.call]],
|
| 2215 |
- a parameter of a user-defined operator [[over.oper]],
|
| 2216 |
- the return value of a function, operator function, or conversion
|
| 2217 |
[[stmt.return]],
|
| 2218 |
- an explicit type conversion
|
| 2219 |
[[expr.type.conv]], [[expr.static.cast]], [[expr.cast]], or
|
| 2220 |
-
- a
|
| 2221 |
|
| 2222 |
-
|
|
|
|
|
|
|
|
|
|
| 2223 |
|
| 2224 |
[*Note 1*: Any redundant set of parentheses surrounding the function
|
| 2225 |
name is ignored [[expr.prim.paren]]. — *end note*]
|
| 2226 |
|
| 2227 |
If there is no target, all non-template functions named are selected.
|
|
@@ -2250,17 +2389,17 @@ All functions with associated constraints that are not satisfied
|
|
| 2250 |
[[temp.constr.decl]] are eliminated from the set of selected functions.
|
| 2251 |
If more than one function in the set remains, all function template
|
| 2252 |
specializations in the set are eliminated if the set also contains a
|
| 2253 |
function that is not a function template specialization. Any given
|
| 2254 |
non-template function `F0` is eliminated if the set contains a second
|
| 2255 |
-
non-template function that is more constrained than
|
| 2256 |
-
|
| 2257 |
-
|
| 2258 |
-
|
| 2259 |
-
|
| 2260 |
-
|
| 2261 |
-
|
| 2262 |
|
| 2263 |
[*Example 1*:
|
| 2264 |
|
| 2265 |
``` cpp
|
| 2266 |
int f(double);
|
|
@@ -2274,12 +2413,15 @@ void g() {
|
|
| 2274 |
(int (*)(int))&f; // cast expression as selector
|
| 2275 |
}
|
| 2276 |
```
|
| 2277 |
|
| 2278 |
The initialization of `pfe` is ill-formed because no `f()` with type
|
| 2279 |
-
`int(...)` has been declared, and not because of any ambiguity.
|
| 2280 |
-
|
|
|
|
|
|
|
|
|
|
| 2281 |
|
| 2282 |
``` cpp
|
| 2283 |
struct X {
|
| 2284 |
int f(int);
|
| 2285 |
static int f(long);
|
|
@@ -2294,10 +2436,27 @@ int (X::*p5)(int) = &(X::f); // error: wrong syntax for
|
|
| 2294 |
int (*p6)(long) = &(X::f); // OK
|
| 2295 |
```
|
| 2296 |
|
| 2297 |
— *end example*]
|
| 2298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2299 |
[*Note 4*: If `f` and `g` are both overload sets, the Cartesian product
|
| 2300 |
of possibilities is considered to resolve `f(&g)`, or the equivalent
|
| 2301 |
expression `f(g)`. — *end note*]
|
| 2302 |
|
| 2303 |
[*Note 5*:
|
|
@@ -2331,10 +2490,11 @@ operator-function-id:
|
|
| 2331 |
operator operator
|
| 2332 |
```
|
| 2333 |
|
| 2334 |
``` bnf
|
| 2335 |
%% Ed. note: character protrusion would misalign various operators.
|
|
|
|
| 2336 |
operator: one of
|
| 2337 |
'new delete new[] delete[] co_await ( ) [ ] -> ->*'
|
| 2338 |
'~ ! + - * / % ^ &'
|
| 2339 |
'| = += -= *= /= %= ^= &='
|
| 2340 |
'|= == != < > <= >= <=> &&'
|
|
@@ -2389,44 +2549,39 @@ explicitly stated in [[basic.stc.dynamic]].
|
|
| 2389 |
|
| 2390 |
The `co_await` operator is described completely in [[expr.await]]. The
|
| 2391 |
attributes and restrictions found in the rest of [[over.oper]] do not
|
| 2392 |
apply to it unless explicitly stated in [[expr.await]].
|
| 2393 |
|
| 2394 |
-
An operator function shall
|
| 2395 |
-
|
| 2396 |
-
|
| 2397 |
-
|
| 2398 |
-
|
| 2399 |
-
|
| 2400 |
-
|
| 2401 |
-
|
| 2402 |
-
|
| 2403 |
-
|
| 2404 |
-
class types by defining operator functions that implement these
|
| 2405 |
-
operators. Likewise, the meaning of the operators (unary) `&` and `,`
|
| 2406 |
-
(comma) can be changed for specific enumeration types. Operator
|
| 2407 |
-
functions are inherited in the same manner as other base class
|
| 2408 |
-
functions.
|
| 2409 |
|
| 2410 |
An operator function shall be a prefix unary, binary, function call,
|
| 2411 |
subscripting, class member access, increment, or decrement operator
|
| 2412 |
function.
|
| 2413 |
|
| 2414 |
[*Note 3*: The identities among certain predefined operators applied to
|
| 2415 |
-
|
| 2416 |
-
functions. Some predefined operators, such as `+=`, require an
|
| 2417 |
-
to be an lvalue when applied to
|
| 2418 |
-
operator functions. — *end note*]
|
| 2419 |
|
| 2420 |
An operator function cannot have default arguments [[dcl.fct.default]],
|
| 2421 |
except where explicitly stated below. Operator functions cannot have
|
| 2422 |
more or fewer parameters than the number required for the corresponding
|
| 2423 |
operator, as described in the rest of [[over.oper]].
|
| 2424 |
|
| 2425 |
-
Operators not mentioned explicitly in subclauses [[over.
|
| 2426 |
-
[[over.inc]] act as ordinary unary and binary operators obeying
|
| 2427 |
-
rules of [[over.unary]] or [[over.binary]].
|
| 2428 |
|
| 2429 |
### Unary operators <a id="over.unary">[[over.unary]]</a>
|
| 2430 |
|
| 2431 |
A *prefix unary operator function* is a function named `operator@` for a
|
| 2432 |
prefix *unary-operator* `@` [[expr.unary.op]] that is either a
|
|
@@ -2484,11 +2639,11 @@ function for a relational operator [[expr.rel]]. A
|
|
| 2484 |
three-way comparison operator [[expr.spaceship]]. A
|
| 2485 |
*comparison operator function* is an equality operator function, a
|
| 2486 |
relational operator function, or a three-way comparison operator
|
| 2487 |
function.
|
| 2488 |
|
| 2489 |
-
#### Simple assignment <a id="over.
|
| 2490 |
|
| 2491 |
A *simple assignment operator function* is a binary operator function
|
| 2492 |
named `operator=`. A simple assignment operator function shall be a
|
| 2493 |
non-static member function.
|
| 2494 |
|
|
@@ -2816,12 +2971,13 @@ bool operator>=(T, T);
|
|
| 2816 |
R operator<=>(T, T);
|
| 2817 |
```
|
| 2818 |
|
| 2819 |
where `R` is the result type specified in [[expr.spaceship]].
|
| 2820 |
|
| 2821 |
-
For every `T`, where `T` is a pointer-to-member type
|
| 2822 |
-
`std::nullptr_t`, there exist candidate operator functions of the
|
|
|
|
| 2823 |
|
| 2824 |
``` cpp
|
| 2825 |
bool operator==(T, T);
|
| 2826 |
bool operator!=(T, T);
|
| 2827 |
```
|
|
@@ -2923,21 +3079,21 @@ T operator?:(bool, T, T);
|
|
| 2923 |
|
| 2924 |
## User-defined literals <a id="over.literal">[[over.literal]]</a>
|
| 2925 |
|
| 2926 |
``` bnf
|
| 2927 |
literal-operator-id:
|
| 2928 |
-
operator
|
| 2929 |
operator user-defined-string-literal
|
| 2930 |
```
|
| 2931 |
|
| 2932 |
-
The *
|
| 2933 |
-
|
| 2934 |
-
|
| 2935 |
-
*
|
| 2936 |
-
|
| 2937 |
-
|
| 2938 |
-
|
| 2939 |
[[usrlit.suffix]]. A declaration whose *literal-operator-id* uses such a
|
| 2940 |
literal suffix identifier is ill-formed, no diagnostic required.
|
| 2941 |
|
| 2942 |
A declaration whose *declarator-id* is a *literal-operator-id* shall
|
| 2943 |
declare a function or function template that belongs to a namespace (it
|
|
@@ -2972,17 +3128,17 @@ is ill-formed.
|
|
| 2972 |
A *raw literal operator* is a literal operator with a single parameter
|
| 2973 |
whose type is `const char*`.
|
| 2974 |
|
| 2975 |
A *numeric literal operator template* is a literal operator template
|
| 2976 |
whose *template-parameter-list* has a single *template-parameter* that
|
| 2977 |
-
is a
|
| 2978 |
type `char`. A *string literal operator template* is a literal operator
|
| 2979 |
-
template whose *template-parameter-list* comprises a single
|
| 2980 |
-
*
|
| 2981 |
-
operator template shall have an
|
| 2982 |
-
shall declare either a numeric
|
| 2983 |
-
literal operator template.
|
| 2984 |
|
| 2985 |
Literal operators and literal operator templates shall not have C
|
| 2986 |
language linkage.
|
| 2987 |
|
| 2988 |
[*Note 1*: Literal operators and literal operator templates are usually
|
|
@@ -3057,35 +3213,37 @@ extern "C" void operator ""_m(long double); // error: C language linkage
|
|
| 3057 |
[dcl.init]: dcl.md#dcl.init
|
| 3058 |
[dcl.init.aggr]: dcl.md#dcl.init.aggr
|
| 3059 |
[dcl.init.list]: dcl.md#dcl.init.list
|
| 3060 |
[dcl.init.ref]: dcl.md#dcl.init.ref
|
| 3061 |
[dcl.init.string]: dcl.md#dcl.init.string
|
|
|
|
| 3062 |
[dcl.type.class.deduct]: dcl.md#dcl.type.class.deduct
|
| 3063 |
[dcl.type.simple]: dcl.md#dcl.type.simple
|
| 3064 |
[depr.lit]: future.md#depr.lit
|
| 3065 |
[expr.arith.conv]: expr.md#expr.arith.conv
|
| 3066 |
-
[expr.
|
| 3067 |
[expr.await]: expr.md#expr.await
|
| 3068 |
[expr.call]: expr.md#expr.call
|
| 3069 |
[expr.cast]: expr.md#expr.cast
|
| 3070 |
[expr.compound]: expr.md#expr.compound
|
| 3071 |
[expr.cond]: expr.md#expr.cond
|
| 3072 |
[expr.eq]: expr.md#expr.eq
|
| 3073 |
[expr.mptr.oper]: expr.md#expr.mptr.oper
|
| 3074 |
[expr.pre.incr]: expr.md#expr.pre.incr
|
| 3075 |
[expr.prim.paren]: expr.md#expr.prim.paren
|
|
|
|
| 3076 |
[expr.prim.this]: expr.md#expr.prim.this
|
| 3077 |
[expr.rel]: expr.md#expr.rel
|
| 3078 |
[expr.spaceship]: expr.md#expr.spaceship
|
| 3079 |
[expr.static.cast]: expr.md#expr.static.cast
|
| 3080 |
[expr.sub]: expr.md#expr.sub
|
| 3081 |
[expr.type.conv]: expr.md#expr.type.conv
|
| 3082 |
[expr.unary.op]: expr.md#expr.unary.op
|
| 3083 |
[lex.ext]: lex.md#lex.ext
|
| 3084 |
[namespace.udecl]: dcl.md#namespace.udecl
|
| 3085 |
[over]: #over
|
| 3086 |
-
[over.
|
| 3087 |
[over.best.ics]: #over.best.ics
|
| 3088 |
[over.best.ics.general]: #over.best.ics.general
|
| 3089 |
[over.binary]: #over.binary
|
| 3090 |
[over.binary.general]: #over.binary.general
|
| 3091 |
[over.built]: #over.built
|
|
|
|
| 4 |
|
| 5 |
[*Note 1*: Each of two or more entities with the same name in the same
|
| 6 |
scope, which must be functions or function templates, is commonly called
|
| 7 |
an “overload”. — *end note*]
|
| 8 |
|
| 9 |
+
When a function is designated in a call, which function declaration is
|
| 10 |
+
being referenced and the validity of the call are determined by
|
| 11 |
+
comparing the types of the arguments at the point of use with the types
|
| 12 |
+
of the parameters in the declarations in the overload set. This function
|
| 13 |
selection process is called *overload resolution* and is defined in
|
| 14 |
[[over.match]].
|
| 15 |
|
| 16 |
+
[*Note 2*: Overload sets are formed by *id-expression*s naming
|
| 17 |
+
functions and function templates and by *splice-expression*s designating
|
| 18 |
+
entities of the same kinds. — *end note*]
|
| 19 |
+
|
| 20 |
[*Example 1*:
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
double abs(double);
|
| 24 |
int abs(int);
|
|
|
|
| 125 |
- “lvalue reference to cv `X`” for functions declared without a
|
| 126 |
*ref-qualifier* or with the `&` *ref-qualifier*
|
| 127 |
- “rvalue reference to cv `X`” for functions declared with the `&&`
|
| 128 |
*ref-qualifier*
|
| 129 |
|
| 130 |
+
where `X` is the class of which the function is a direct member and cv
|
| 131 |
+
is the cv-qualification on the member function declaration.
|
| 132 |
|
| 133 |
[*Example 1*: For a `const` member function of class `X`, the extra
|
| 134 |
parameter is assumed to have type “lvalue reference to
|
| 135 |
`const X`”. — *end example*]
|
| 136 |
|
|
|
|
| 282 |
member function, the program is ill-formed.
|
| 283 |
|
| 284 |
[*Note 2*: The resolution of the address of an overload set in other
|
| 285 |
contexts is described in [[over.over]]. — *end note*]
|
| 286 |
|
| 287 |
+
##### Call to designated function <a id="over.call.func">[[over.call.func]]</a>
|
| 288 |
|
| 289 |
Of interest in [[over.call.func]] are only those function calls in
|
| 290 |
+
which the *postfix-expression* ultimately contains an *id-expression* or
|
| 291 |
+
*splice-expression* that designates one or more functions. Such a
|
| 292 |
+
*postfix-expression*, perhaps nested arbitrarily deep in parentheses,
|
| 293 |
+
has one of the following forms:
|
| 294 |
|
| 295 |
``` bnf
|
| 296 |
postfix-expression:
|
| 297 |
postfix-expression '.' id-expression
|
| 298 |
+
postfix-expression '.' splice-expression
|
| 299 |
postfix-expression '->' id-expression
|
| 300 |
+
postfix-expression '->' splice-expression
|
| 301 |
+
id-expression
|
| 302 |
+
splice-expression
|
| 303 |
```
|
| 304 |
|
| 305 |
These represent two syntactic subcategories of function calls: qualified
|
| 306 |
function calls and unqualified function calls.
|
| 307 |
|
| 308 |
+
In qualified function calls, the function is designated by an
|
| 309 |
+
*id-expression* or *splice-expression* E preceded by an `->` or `.`
|
| 310 |
+
operator. Since the construct `A->B` is generally equivalent to
|
| 311 |
+
`(*A).B`, the rest of [[over]] assumes, without loss of generality, that
|
| 312 |
+
all member function calls have been normalized to the form that uses an
|
| 313 |
+
object and the `.` operator. Furthermore, [[over]] assumes that the
|
| 314 |
+
*postfix-expression* that is the left operand of the `.` operator has
|
| 315 |
+
type “cv `T`” where `T` denotes a class.[^2]
|
| 316 |
|
| 317 |
+
The set of candidate functions either is the set found by name lookup
|
| 318 |
+
[[class.member.lookup]] if E is an *id-expression* or is the set
|
| 319 |
+
determined as specified in [[expr.prim.splice]] if E is a
|
| 320 |
+
*splice-expression*. The argument list is the *expression-list* in the
|
| 321 |
+
call augmented by the addition of the left operand of the `.` operator
|
| 322 |
+
in the normalized member function call as the implied object argument
|
| 323 |
+
[[over.match.funcs]].
|
| 324 |
|
| 325 |
+
In unqualified function calls, the function is designated by an
|
| 326 |
+
*id-expression* or a *splice-expression* E. The set of candidate
|
| 327 |
+
functions either is the set found by name lookup [[basic.lookup]] if E
|
| 328 |
+
is an *id-expression* or is the set determined as specified in
|
| 329 |
+
[[expr.prim.splice]] if E is a *splice-expression*. The set of candidate
|
| 330 |
+
functions consists either entirely of non-member functions or entirely
|
| 331 |
+
of member functions of some class `T`. In the former case or if E is
|
| 332 |
+
either a *splice-expression* or the address of an overload set, the
|
| 333 |
+
argument list is the same as the *expression-list* in the call.
|
| 334 |
+
Otherwise, the argument list is the *expression-list* in the call
|
| 335 |
+
augmented by the addition of an implied object argument as in a
|
| 336 |
+
qualified function call. If the current class is, or is derived from,
|
| 337 |
+
`T`, and the keyword `this` [[expr.prim.this]] refers to it,
|
| 338 |
|
| 339 |
+
- if the unqualified function call appears in a precondition assertion
|
| 340 |
+
of a constructor or a postcondition assertion of a destructor and
|
| 341 |
+
overload resolution selects a non-static member function, the call is
|
| 342 |
+
ill-formed;
|
| 343 |
+
- otherwise, the implied object argument is `(*this)`.
|
| 344 |
+
|
| 345 |
+
Otherwise,
|
| 346 |
+
|
| 347 |
+
- if overload resolution selects a non-static member function, the call
|
| 348 |
+
is ill-formed;
|
| 349 |
+
- otherwise, a contrived object of type `T` becomes the implied object
|
| 350 |
+
argument.[^3]
|
| 351 |
|
| 352 |
[*Example 1*:
|
| 353 |
|
| 354 |
``` cpp
|
| 355 |
struct C {
|
| 356 |
+
bool a();
|
| 357 |
void b() {
|
| 358 |
a(); // OK, (*this).a()
|
| 359 |
}
|
| 360 |
|
| 361 |
void c(this const C&); // #1
|
|
|
|
| 388 |
void k(this int);
|
| 389 |
operator int() const;
|
| 390 |
void m(this const C& c) {
|
| 391 |
c.k(); // OK
|
| 392 |
}
|
| 393 |
+
|
| 394 |
+
C()
|
| 395 |
+
pre(a()) // error: implied this in constructor precondition
|
| 396 |
+
pre(this->a()) // OK
|
| 397 |
+
post(a()); // OK
|
| 398 |
+
~C()
|
| 399 |
+
pre(a()) // OK
|
| 400 |
+
post(a()) // error: implied this in destructor postcondition
|
| 401 |
+
post(this->a()); // OK
|
| 402 |
};
|
| 403 |
```
|
| 404 |
|
| 405 |
— *end example*]
|
| 406 |
|
|
|
|
| 427 |
returning `R`”, a *surrogate call function* with the unique name
|
| 428 |
*call-function* and having the form
|
| 429 |
|
| 430 |
``` bnf
|
| 431 |
'R' *call-function* '(' conversion-type-id \ %
|
| 432 |
+
'F, P₁ a₁, …, Pₙ aₙ)' '{' return 'F (a₁, …, aₙ); }'
|
| 433 |
```
|
| 434 |
|
| 435 |
is also considered as a candidate function. Similarly, surrogate call
|
| 436 |
functions are added to the set of candidate functions for each
|
| 437 |
non-explicit conversion function declared in a base class of `T`
|
|
|
|
| 510 |
built-in operator [[expr.compound]].
|
| 511 |
|
| 512 |
**Table: Relationship between operator and function call notation** <a id="over.match.oper">[over.match.oper]</a>
|
| 513 |
|
| 514 |
| Subclause | Expression | As member function | As non-member function |
|
| 515 |
+
| --------------- | ---------- | ------------------- | ---------------------- |
|
| 516 |
| (a)} |
|
| 517 |
| (a, b)} |
|
| 518 |
+
| [[over.assign]] | `a=b` | `(a).operator= (b)` | |
|
| 519 |
| [[over.sub]] | `a[b]` | `(a).operator[](b)` | |
|
| 520 |
| [[over.ref]] | `a->` | `(a).operator->( )` | |
|
| 521 |
| (a, 0)} |
|
| 522 |
|
| 523 |
|
|
|
|
| 614 |
bool d1 = 0 == D(); // OK, calls reversed #4; #5 does not forbid #4 as a rewrite target
|
| 615 |
```
|
| 616 |
|
| 617 |
— *end example*]
|
| 618 |
|
| 619 |
+
For the first parameter of the built-in assignment operators, only
|
| 620 |
+
standard conversion sequences [[over.ics.scs]] are considered.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 621 |
|
| 622 |
For all other operators, no such restrictions apply.
|
| 623 |
|
| 624 |
The set of candidate functions for overload resolution for some operator
|
| 625 |
`@` is the union of the member candidates, the non-member candidates,
|
|
|
|
| 728 |
|
| 729 |
When objects of class type are direct-initialized [[dcl.init]],
|
| 730 |
copy-initialized from an expression of the same or a derived class type
|
| 731 |
[[dcl.init]], or default-initialized [[dcl.init]], overload resolution
|
| 732 |
selects the constructor. For direct-initialization or
|
| 733 |
+
default-initialization (including default-initialization in the context
|
| 734 |
+
of copy-list-initialization), the candidate functions are all the
|
| 735 |
+
constructors of the class of the object being initialized. Otherwise,
|
| 736 |
+
the candidate functions are all the non-explicit constructors
|
| 737 |
+
[[class.conv.ctor]] of that class. The argument list is the
|
| 738 |
+
*expression-list* or *assignment-expression* of the *initializer*. For
|
| 739 |
+
default-initialization in the context of copy-list-initialization, if an
|
| 740 |
+
explicit constructor is chosen, the initialization is ill-formed.
|
| 741 |
|
| 742 |
#### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
|
| 743 |
|
| 744 |
Under the conditions specified in [[dcl.init]], as part of a
|
| 745 |
copy-initialization of an object of class type, a user-defined
|
|
|
|
| 752 |
corresponding non-reference copy-initialization. — *end note*]
|
| 753 |
|
| 754 |
Assuming that “*cv1* `T`” is the type of the object being initialized,
|
| 755 |
with `T` a class type, the candidate functions are selected as follows:
|
| 756 |
|
| 757 |
+
- The non-explicit constructors [[class.conv.ctor]] of `T` are candidate
|
| 758 |
functions.
|
| 759 |
- When the type of the initializer expression is a class type “cv `S`”,
|
| 760 |
conversion functions are considered. The permissible types for
|
| 761 |
non-explicit conversion functions are `T` and any class derived from
|
| 762 |
`T`. When initializing a temporary object [[class.mem]] to be bound to
|
|
|
|
| 803 |
conversion function to be invoked. Assuming that “reference to *cv1*
|
| 804 |
`T`” is the type of the reference being initialized, the candidate
|
| 805 |
functions are selected as follows:
|
| 806 |
|
| 807 |
- Let R be a set of types including
|
| 808 |
+
- “lvalue reference to *cv2* `T2`” (when converting to an lvalue) and
|
| 809 |
+
- “*cv2* `T2`” and “rvalue reference to *cv2* `T2`” (when converting
|
| 810 |
+
to an rvalue or an lvalue of function type)
|
|
|
|
| 811 |
|
| 812 |
for any `T2`. The permissible types for non-explicit conversion
|
| 813 |
functions are the members of R where “*cv1* `T`” is
|
| 814 |
reference-compatible [[dcl.init.ref]] with “*cv2* `T2`”. For
|
| 815 |
direct-initialization, the permissible types for explicit conversion
|
|
|
|
| 842 |
|
| 843 |
In copy-list-initialization, if an explicit constructor is chosen, the
|
| 844 |
initialization is ill-formed.
|
| 845 |
|
| 846 |
[*Note 1*: This differs from other situations
|
| 847 |
+
[[over.match.ctor]], [[over.match.copy]], where only non-explicit
|
| 848 |
constructors are considered for copy-initialization. This restriction
|
| 849 |
only applies if this initialization is part of the final result of
|
| 850 |
overload resolution. — *end note*]
|
| 851 |
|
| 852 |
#### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
|
| 853 |
|
| 854 |
When resolving a placeholder for a deduced class type
|
| 855 |
+
[[dcl.type.class.deduct]] where the *template-name* or
|
| 856 |
+
*splice-type-specifier* designates a primary class template `C`, a set
|
| 857 |
+
of functions and function templates, called the guides of `C`, is formed
|
| 858 |
+
comprising:
|
| 859 |
|
| 860 |
- If `C` is defined, for each constructor of `C`, a function template
|
| 861 |
with the following properties:
|
| 862 |
- The template parameters are the template parameters of `C` followed
|
| 863 |
by the template parameters (including default template arguments) of
|
| 864 |
the constructor, if any.
|
| 865 |
+
- The associated constraints [[temp.constr.decl]] are the conjunction
|
| 866 |
+
of the associated constraints of `C` and the associated constraints
|
| 867 |
+
of the constructor, if any. \[*Note 1*: A *constraint-expression* in
|
| 868 |
+
the *template-head* of `C` is checked for satisfaction before any
|
| 869 |
+
constraints from the *template-head* or trailing *requires-clause*
|
| 870 |
+
of the constructor. — *end note*]
|
| 871 |
+
- The *parameter-declaration-clause* is that of the constructor.
|
| 872 |
- The return type is the class template specialization designated by
|
| 873 |
`C` and template arguments corresponding to the template parameters
|
| 874 |
of `C`.
|
| 875 |
- If `C` is not defined or does not declare any constructors, an
|
| 876 |
additional function template derived as above from a hypothetical
|
| 877 |
constructor `C()`.
|
| 878 |
- An additional function template derived as above from a hypothetical
|
| 879 |
constructor `C(C)`, called the *copy deduction candidate*.
|
| 880 |
- For each *deduction-guide*, a function or function template with the
|
| 881 |
following properties:
|
| 882 |
+
- The *template-head*, if any, and *parameter-declaration-clause* are
|
| 883 |
+
those of the *deduction-guide*.
|
| 884 |
- The return type is the *simple-template-id* of the
|
| 885 |
*deduction-guide*.
|
| 886 |
|
| 887 |
In addition, if `C` is defined and its definition satisfies the
|
| 888 |
conditions for an aggregate class [[dcl.init.aggr]] with the assumption
|
|
|
|
| 942 |
template argument list is a specialization of `A` with the template
|
| 943 |
argument list of `A` [[temp.dep.type]] having a member typedef `type`
|
| 944 |
designating a template specialization with the template argument list of
|
| 945 |
`A` but with `C` as the template.
|
| 946 |
|
| 947 |
+
[*Note 2*: Equivalently, the template parameter list of the
|
| 948 |
specialization is that of `C`, the template argument list of the
|
| 949 |
specialization is `B`, and the member typedef names `C` with the
|
| 950 |
template argument list of `C`. — *end note*]
|
| 951 |
|
| 952 |
[*Example 1*:
|
|
|
|
| 999 |
```
|
| 1000 |
|
| 1001 |
— *end example*]
|
| 1002 |
|
| 1003 |
When resolving a placeholder for a deduced class type
|
| 1004 |
+
[[dcl.type.simple]] where the *template-name* or *splice-type-specifier*
|
| 1005 |
+
designates an alias template `A`, the *defining-type-id* of `A` must be
|
| 1006 |
+
of the form
|
| 1007 |
|
| 1008 |
``` bnf
|
| 1009 |
typenameₒₚₜ nested-name-specifierₒₚₜ templateₒₚₜ simple-template-id
|
| 1010 |
```
|
| 1011 |
|
|
|
|
| 1245 |
- A candidate function having fewer than m parameters is viable only if
|
| 1246 |
it has an ellipsis in its parameter list [[dcl.fct]]. For the purposes
|
| 1247 |
of overload resolution, any argument for which there is no
|
| 1248 |
corresponding parameter is considered to “match the ellipsis”
|
| 1249 |
[[over.ics.ellipsis]].
|
| 1250 |
+
- A candidate function `C` having more than m parameters is viable only
|
| 1251 |
+
if the set of scopes G, as defined below, is not empty. G consists of
|
| 1252 |
+
every scope X that satisfies all of the following:
|
| 1253 |
+
- There is a declaration of `C`, whose host scope is X, considered by
|
| 1254 |
+
the overload resolution.
|
| 1255 |
+
- For every $k^\textrm{th}$ parameter P where k \> m, there is a
|
| 1256 |
+
reachable declaration, whose host scope is X, that specifies a
|
| 1257 |
+
default argument [[dcl.fct.default]] for P.
|
| 1258 |
+
|
| 1259 |
+
If `C` is selected as the best viable function [[over.match.best]]:
|
| 1260 |
+
- G shall contain exactly one scope (call it S).
|
| 1261 |
+
- If the candidates are denoted by a *splice-expression*, then S shall
|
| 1262 |
+
not be a block scope.
|
| 1263 |
+
- The default arguments used in the call to `C` are the default
|
| 1264 |
+
arguments specified by the reachable declarations whose host scope
|
| 1265 |
+
is S.
|
| 1266 |
+
|
| 1267 |
+
For the purposes of overload resolution, the parameter list is
|
| 1268 |
+
truncated on the right, so that there are exactly m parameters.
|
| 1269 |
+
|
| 1270 |
+
[*Example 1*:
|
| 1271 |
+
|
| 1272 |
+
``` cpp
|
| 1273 |
+
namespace A {
|
| 1274 |
+
extern "C" void f(int, int = 5);
|
| 1275 |
+
extern "C" void f(int = 6, int);
|
| 1276 |
+
}
|
| 1277 |
+
namespace B {
|
| 1278 |
+
extern "C" void f(int, int = 7);
|
| 1279 |
+
}
|
| 1280 |
+
|
| 1281 |
+
void use() {
|
| 1282 |
+
[:^^A::f:](3, 4); // OK, default argument was not used for viability
|
| 1283 |
+
[:^^A::f:](3); // error: default argument provided by declarations from two scopes
|
| 1284 |
+
[:^^A::f:](); // OK, default arguments provided by declarations in the scope of A
|
| 1285 |
+
|
| 1286 |
+
using A::f;
|
| 1287 |
+
using B::f;
|
| 1288 |
+
f(3, 4); // OK, default argument was not used for viability
|
| 1289 |
+
f(3); // error: default argument provided by declaration from two scopes
|
| 1290 |
+
f(); // OK, default arguments provided by declarations in the scope of A
|
| 1291 |
+
|
| 1292 |
+
void g(int = 8);
|
| 1293 |
+
g(); // OK
|
| 1294 |
+
[:^^g:](); // error: host scope is block scope
|
| 1295 |
+
}
|
| 1296 |
+
|
| 1297 |
+
void h(int = 7);
|
| 1298 |
+
constexpr std::meta::info r = ^^h;
|
| 1299 |
+
void poison() {
|
| 1300 |
+
void h(int = 8);
|
| 1301 |
+
h(); // OK, calls h(8)
|
| 1302 |
+
[:^^h:](); // error: default argument provided by declarations from two scopes
|
| 1303 |
+
}
|
| 1304 |
+
void call_h() {
|
| 1305 |
+
[:^^h:](); // error: default argument provided by declarations from two scopes
|
| 1306 |
+
[:r:](); // error: default argument provided by declarations from two scopes
|
| 1307 |
+
}
|
| 1308 |
+
|
| 1309 |
+
template<typename... Ts>
|
| 1310 |
+
int k(int = 3, Ts...);
|
| 1311 |
+
int i = k<int>(); // error: no default argument for the second parameter
|
| 1312 |
+
int j = k<>(); // OK
|
| 1313 |
+
```
|
| 1314 |
+
|
| 1315 |
+
— *end example*]
|
| 1316 |
|
| 1317 |
Second, for a function to be viable, if it has associated constraints
|
| 1318 |
[[temp.constr.decl]], those constraints shall be satisfied
|
| 1319 |
[[temp.constr.constr]].
|
| 1320 |
|
|
|
|
| 1345 |
|
| 1346 |
- for some argument j, ICSʲ(`F₁`) is a better conversion sequence than
|
| 1347 |
ICSʲ(`F₂`), or, if not that,
|
| 1348 |
- the context is an initialization by user-defined conversion (see
|
| 1349 |
[[dcl.init]], [[over.match.conv]], and [[over.match.ref]]) and the
|
| 1350 |
+
standard conversion sequence from the result of `F₁` to the
|
| 1351 |
destination type (i.e., the type of the entity being initialized) is a
|
| 1352 |
better conversion sequence than the standard conversion sequence from
|
| 1353 |
+
the result of `F₂` to the destination type
|
| 1354 |
\[*Example 1*:
|
| 1355 |
``` cpp
|
| 1356 |
struct A {
|
| 1357 |
A();
|
| 1358 |
operator int();
|
|
|
|
| 1366 |
|
| 1367 |
— *end example*]
|
| 1368 |
or, if not that,
|
| 1369 |
- the context is an initialization by conversion function for direct
|
| 1370 |
reference binding [[over.match.ref]] of a reference to function type,
|
| 1371 |
+
the return type of `F₁` is the same kind of reference (lvalue or
|
| 1372 |
rvalue) as the reference being initialized, and the return type of
|
| 1373 |
+
`F₂` is not
|
| 1374 |
\[*Example 2*:
|
| 1375 |
``` cpp
|
| 1376 |
template <class T> struct A {
|
| 1377 |
operator T&(); // #1
|
| 1378 |
operator T&&(); // #2
|
|
|
|
| 1383 |
Fn&& rf = a; // calls #2
|
| 1384 |
```
|
| 1385 |
|
| 1386 |
— *end example*]
|
| 1387 |
or, if not that,
|
| 1388 |
+
- `F₁` is not a function template specialization and `F₂` is a function
|
| 1389 |
template specialization, or, if not that,
|
| 1390 |
+
- `F₁` and `F₂` are function template specializations, and the function
|
| 1391 |
+
template for `F₁` is more specialized than the template for `F₂`
|
| 1392 |
according to the partial ordering rules described in
|
| 1393 |
[[temp.func.order]], or, if not that,
|
| 1394 |
+
- `F₁` and `F₂` are non-template functions and `F₁` is more
|
| 1395 |
+
partial-ordering-constrained than `F₂` [[temp.constr.order]]
|
| 1396 |
+
\[*Example 3*:
|
| 1397 |
+
``` cpp
|
| 1398 |
+
template <typename T = int>
|
| 1399 |
+
struct S {
|
| 1400 |
+
constexpr void f(); // #1
|
| 1401 |
+
constexpr void f(this S&) requires true; // #2
|
| 1402 |
+
};
|
| 1403 |
+
|
| 1404 |
+
void test() {
|
| 1405 |
+
S<> s;
|
| 1406 |
+
s.f(); // calls #2
|
| 1407 |
+
}
|
| 1408 |
+
```
|
| 1409 |
+
|
| 1410 |
+
— *end example*]
|
| 1411 |
+
or, if not that,
|
| 1412 |
+
- `F₁` is a constructor for a class `D`, `F₂` is a constructor for a
|
| 1413 |
base class `B` of `D`, and for all arguments the corresponding
|
| 1414 |
+
parameters of `F₁` and `F₂` have the same type
|
| 1415 |
+
\[*Example 4*:
|
| 1416 |
``` cpp
|
| 1417 |
struct A {
|
| 1418 |
A(int = 0);
|
| 1419 |
};
|
| 1420 |
|
|
|
|
| 1428 |
}
|
| 1429 |
```
|
| 1430 |
|
| 1431 |
— *end example*]
|
| 1432 |
or, if not that,
|
| 1433 |
+
- `F₂` is a rewritten candidate [[over.match.oper]] and `F₁` is not
|
| 1434 |
+
\[*Example 5*:
|
| 1435 |
``` cpp
|
| 1436 |
struct S {
|
| 1437 |
friend auto operator<=>(const S&, const S&) = default; // #1
|
| 1438 |
friend bool operator<(const S&, const S&); // #2
|
| 1439 |
};
|
| 1440 |
bool b = S() < S(); // calls #2
|
| 1441 |
```
|
| 1442 |
|
| 1443 |
— *end example*]
|
| 1444 |
or, if not that,
|
| 1445 |
+
- `F₁` and `F₂` are rewritten candidates, and `F₂` is a synthesized
|
| 1446 |
+
candidate with reversed order of parameters and `F₁` is not
|
| 1447 |
+
\[*Example 6*:
|
| 1448 |
``` cpp
|
| 1449 |
struct S {
|
| 1450 |
friend std::weak_ordering operator<=>(const S&, int); // #1
|
| 1451 |
friend std::weak_ordering operator<=>(int, const S&); // #2
|
| 1452 |
};
|
| 1453 |
bool b = 1 < S(); // calls #2
|
| 1454 |
```
|
| 1455 |
|
| 1456 |
— *end example*]
|
| 1457 |
+
or, if not that,
|
| 1458 |
+
- `F₁` and `F₂` are generated from class template argument deduction
|
| 1459 |
+
[[over.match.class.deduct]] for a class `D`, and `F₂` is generated
|
| 1460 |
+
from inheriting constructors from a base class of `D` while `F₁` is
|
| 1461 |
not, and for each explicit function argument, the corresponding
|
| 1462 |
+
parameters of `F₁` and `F₂` are either both ellipses or have the same
|
| 1463 |
type, or, if not that,
|
| 1464 |
+
- `F₁` is generated from a *deduction-guide* [[over.match.class.deduct]]
|
| 1465 |
+
and `F₂` is not, or, if not that,
|
| 1466 |
+
- `F₁` is the copy deduction candidate [[over.match.class.deduct]] and
|
| 1467 |
+
`F₂` is not, or, if not that,
|
| 1468 |
+
- `F₁` is generated from a non-template constructor and `F₂` is
|
| 1469 |
generated from a constructor template.
|
| 1470 |
+
\[*Example 7*:
|
| 1471 |
``` cpp
|
| 1472 |
template <class T> struct A {
|
| 1473 |
using value_type = T;
|
| 1474 |
A(value_type); // #1
|
| 1475 |
A(const A&); // #2
|
|
|
|
| 1497 |
|
| 1498 |
If there is exactly one viable function that is a better function than
|
| 1499 |
all other viable functions, then it is the one selected by overload
|
| 1500 |
resolution; otherwise the call is ill-formed.[^7]
|
| 1501 |
|
| 1502 |
+
[*Example 8*:
|
| 1503 |
|
| 1504 |
``` cpp
|
| 1505 |
void Fcn(const int*, short);
|
| 1506 |
void Fcn(int*, int);
|
| 1507 |
|
|
|
|
| 1520 |
}
|
| 1521 |
```
|
| 1522 |
|
| 1523 |
— *end example*]
|
| 1524 |
|
| 1525 |
+
[*Note 1*: If the best viable function was made viable by one or more
|
| 1526 |
+
default arguments, additional requirements apply
|
| 1527 |
+
[[over.match.viable]]. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1528 |
|
| 1529 |
#### Implicit conversion sequences <a id="over.best.ics">[[over.best.ics]]</a>
|
| 1530 |
|
| 1531 |
##### General <a id="over.best.ics.general">[[over.best.ics.general]]</a>
|
| 1532 |
|
|
|
|
| 1539 |
|
| 1540 |
Implicit conversion sequences are concerned only with the type,
|
| 1541 |
cv-qualification, and value category of the argument and how these are
|
| 1542 |
converted to match the corresponding properties of the parameter.
|
| 1543 |
|
| 1544 |
+
[*Note 1*: Other properties, such as the lifetime, storage duration,
|
| 1545 |
+
linkage, alignment, accessibility of the argument, whether the argument
|
| 1546 |
+
is a bit-field, and whether a function is deleted
|
| 1547 |
+
[[dcl.fct.def.delete]], are ignored. So, although an implicit conversion
|
| 1548 |
+
sequence can be defined for a given argument-parameter pair, the
|
| 1549 |
+
conversion from the argument to the parameter might still be ill-formed
|
| 1550 |
+
in the final analysis. — *end note*]
|
| 1551 |
|
| 1552 |
A well-formed implicit conversion sequence is one of the following
|
| 1553 |
forms:
|
| 1554 |
|
| 1555 |
- a standard conversion sequence [[over.ics.scs]],
|
|
|
|
| 1606 |
[*Note 3*: When the parameter has a class type, this is a conceptual
|
| 1607 |
conversion defined for the purposes of [[over]]; the actual
|
| 1608 |
initialization is defined in terms of constructors and is not a
|
| 1609 |
conversion. — *end note*]
|
| 1610 |
|
| 1611 |
+
When the cv-unqualified version of the type of the argument expression
|
| 1612 |
+
is the same as the parameter type, the implicit conversion sequence is
|
| 1613 |
+
an identity conversion. When the parameter has a class type and the
|
| 1614 |
+
argument expression has a (possibly cv-qualified) derived class type,
|
| 1615 |
+
the implicit conversion sequence is a derived-to-base conversion from
|
| 1616 |
+
the derived class to the base class. A derived-to-base conversion has
|
| 1617 |
+
Conversion rank [[over.ics.scs]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1618 |
|
| 1619 |
[*Note 4*: There is no such standard conversion; this derived-to-base
|
| 1620 |
conversion exists only in the description of implicit conversion
|
| 1621 |
sequences. — *end note*]
|
| 1622 |
|
| 1623 |
+
[*Example 2*: An implicit conversion sequence from an argument of type
|
| 1624 |
+
`const A` to a parameter of type `A` can be formed, even if overload
|
| 1625 |
+
resolution for copy-initialization of `A` from the argument would not
|
| 1626 |
+
find a viable function [[over.match.ctor]], [[over.match.viable]]. The
|
| 1627 |
+
implicit conversion sequence for that case is the identity sequence; it
|
| 1628 |
+
contains no “conversion” from `const A` to `A`. — *end example*]
|
| 1629 |
+
|
| 1630 |
When the parameter is the implicit object parameter of a static member
|
| 1631 |
function, the implicit conversion sequence is a standard conversion
|
| 1632 |
sequence that is neither better nor worse than any other standard
|
| 1633 |
conversion sequence.
|
| 1634 |
|
| 1635 |
In all contexts, when converting to the implicit object parameter or
|
| 1636 |
when converting to the left operand of an assignment operation only
|
| 1637 |
standard conversion sequences are allowed.
|
| 1638 |
|
| 1639 |
+
[*Note 5*: When a conversion to the explicit object parameter occurs,
|
| 1640 |
+
it can include user-defined conversion sequences. — *end note*]
|
| 1641 |
|
| 1642 |
If no conversions are required to match an argument to a parameter type,
|
| 1643 |
the implicit conversion sequence is the standard conversion sequence
|
| 1644 |
consisting of the identity conversion [[over.ics.scs]].
|
| 1645 |
|
|
|
|
| 1746 |
when selecting the best user-defined conversion for a user-defined
|
| 1747 |
conversion sequence (see [[over.match.best]] and [[over.best.ics]]).
|
| 1748 |
|
| 1749 |
If the user-defined conversion is specified by a specialization of a
|
| 1750 |
conversion function template, the second standard conversion sequence
|
| 1751 |
+
shall have Exact Match rank.
|
| 1752 |
|
| 1753 |
A conversion of an expression of class type to the same class type is
|
| 1754 |
given Exact Match rank, and a conversion of an expression of class type
|
| 1755 |
to a base class of that type is given Conversion rank, in spite of the
|
| 1756 |
fact that a constructor (i.e., a user-defined conversion function) is
|
|
|
|
| 1762 |
call is matched with the ellipsis parameter specification of the
|
| 1763 |
function called (see [[expr.call]]).
|
| 1764 |
|
| 1765 |
##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
|
| 1766 |
|
| 1767 |
+
When a parameter of type “reference to cv `T`” binds directly
|
| 1768 |
+
[[dcl.init.ref]] to an argument expression:
|
| 1769 |
+
|
| 1770 |
+
- If the argument expression has a type that is a derived class of the
|
| 1771 |
+
parameter type, the implicit conversion sequence is a derived-to-base
|
| 1772 |
+
conversion [[over.best.ics]].
|
| 1773 |
+
- Otherwise, if the type of the argument is possibly cv-qualified `T`,
|
| 1774 |
+
or if `T` is an array type of unknown bound with element type `U` and
|
| 1775 |
+
the argument has an array type of known bound whose element type is
|
| 1776 |
+
possibly cv-qualified `U`, the implicit conversion sequence is the
|
| 1777 |
+
identity conversion.
|
| 1778 |
+
- Otherwise, if `T` is a function type, the implicit conversion sequence
|
| 1779 |
+
is a function pointer conversion.
|
| 1780 |
+
- Otherwise, the implicit conversion sequence is a qualification
|
| 1781 |
+
conversion.
|
| 1782 |
|
| 1783 |
[*Example 4*:
|
| 1784 |
|
| 1785 |
``` cpp
|
| 1786 |
struct A {};
|
| 1787 |
struct B : public A {} b;
|
| 1788 |
int f(A&);
|
| 1789 |
int f(B&);
|
| 1790 |
int i = f(b); // calls f(B&), an exact match, rather than f(A&), a conversion
|
| 1791 |
+
|
| 1792 |
+
void g() noexcept;
|
| 1793 |
+
int h(void (&)() noexcept); // #1
|
| 1794 |
+
int h(void (&)()); // #2
|
| 1795 |
+
int j = h(g); // calls #1, an exact match, rather than #2, a function pointer conversion
|
| 1796 |
```
|
| 1797 |
|
| 1798 |
— *end example*]
|
| 1799 |
|
| 1800 |
If the parameter binds directly to the result of applying a conversion
|
| 1801 |
function to the argument expression, the implicit conversion sequence is
|
| 1802 |
a user-defined conversion sequence [[over.ics.user]] whose second
|
| 1803 |
+
standard conversion sequence is determined by the above rules.
|
|
|
|
|
|
|
| 1804 |
|
| 1805 |
When a parameter of reference type is not bound directly to an argument
|
| 1806 |
expression, the conversion sequence is the one required to convert the
|
| 1807 |
argument expression to the referenced type according to
|
| 1808 |
[[over.best.ics]]. Conceptually, this conversion sequence corresponds to
|
|
|
|
| 1812 |
|
| 1813 |
Except for an implicit object parameter, for which see
|
| 1814 |
[[over.match.funcs]], an implicit conversion sequence cannot be formed
|
| 1815 |
if it requires binding an lvalue reference other than a reference to a
|
| 1816 |
non-volatile `const` type to an rvalue or binding an rvalue reference to
|
| 1817 |
+
an lvalue of object type.
|
| 1818 |
|
| 1819 |
[*Note 9*: This means, for example, that a candidate function cannot be
|
| 1820 |
a viable function if it has a non-`const` lvalue reference parameter
|
| 1821 |
(other than the implicit object parameter) and the corresponding
|
| 1822 |
argument would require a temporary to be created to initialize the
|
|
|
|
| 1839 |
|
| 1840 |
When an argument is an initializer list [[dcl.init.list]], it is not an
|
| 1841 |
expression and special rules apply for converting it to a parameter
|
| 1842 |
type.
|
| 1843 |
|
| 1844 |
+
If the initializer list is a *designated-initializer-list* and the
|
| 1845 |
+
parameter is not a reference, a conversion is only possible if the
|
| 1846 |
+
parameter has an aggregate type that can be initialized from the
|
| 1847 |
+
initializer list according to the rules for aggregate initialization
|
| 1848 |
+
[[dcl.init.aggr]], in which case the implicit conversion sequence is a
|
| 1849 |
+
user-defined conversion sequence whose second standard conversion
|
| 1850 |
+
sequence is an identity conversion.
|
| 1851 |
|
| 1852 |
[*Note 10*:
|
| 1853 |
|
| 1854 |
Aggregate initialization does not require that the members are declared
|
| 1855 |
in designation order. If, after overload resolution, the order does not
|
|
|
|
| 1905 |
f( {'a','b'} ); // OK, f(initializer_list<int>) integral promotion
|
| 1906 |
f( {1.0} ); // error: narrowing
|
| 1907 |
|
| 1908 |
struct A {
|
| 1909 |
A(std::initializer_list<double>); // #1
|
| 1910 |
+
A(std::initializer_list<std::complex<double>>); // #2
|
| 1911 |
A(std::initializer_list<std::string>); // #3
|
| 1912 |
};
|
| 1913 |
A a{ 1.0,2.0 }; // OK, uses #1
|
| 1914 |
|
| 1915 |
void g(A);
|
|
|
|
| 2153 |
```
|
| 2154 |
|
| 2155 |
— *end example*]
|
| 2156 |
or, if not that,
|
| 2157 |
- `S1` and `S2` include reference bindings [[dcl.init.ref]] and `S1`
|
| 2158 |
+
binds an lvalue reference to an lvalue of function type and `S2`
|
| 2159 |
+
binds an rvalue reference to an lvalue of function type
|
| 2160 |
\[*Example 4*:
|
| 2161 |
``` cpp
|
| 2162 |
int f(void(&)()); // #1
|
| 2163 |
int f(void(&&)()); // #2
|
| 2164 |
void g();
|
|
|
|
| 2166 |
```
|
| 2167 |
|
| 2168 |
— *end example*]
|
| 2169 |
or, if not that,
|
| 2170 |
- `S1` and `S2` differ only in their qualification conversion
|
| 2171 |
+
[[conv.qual]] and yield similar types `T1` and `T2`, respectively
|
| 2172 |
+
(where a standard conversion sequence that is a reference binding is
|
| 2173 |
+
considered to yield the cv-unqualified referenced type), where `T1`
|
| 2174 |
+
and `T2` are not the same type, and `const T2` is
|
| 2175 |
+
reference-compatible with `T1` [[dcl.init.ref]]
|
| 2176 |
\[*Example 5*:
|
| 2177 |
``` cpp
|
| 2178 |
int f(const volatile int *);
|
| 2179 |
int f(const int *);
|
| 2180 |
int i;
|
| 2181 |
int j = f(&i); // calls f(const int*)
|
| 2182 |
+
int g(const int*);
|
| 2183 |
+
int g(const volatile int* const&);
|
| 2184 |
+
int* p;
|
| 2185 |
+
int k = g(p); // calls g(const int*)
|
| 2186 |
```
|
| 2187 |
|
| 2188 |
— *end example*]
|
| 2189 |
or, if not that,
|
| 2190 |
- `S1`
|
| 2191 |
+
and `S2` bind “reference to `T1`” and “reference to `T2`”,
|
| 2192 |
+
respectively [[dcl.init.ref]], where `T1` and `T2` are not the same
|
| 2193 |
+
type, and `T2` is reference-compatible with `T1`
|
|
|
|
|
|
|
| 2194 |
\[*Example 6*:
|
| 2195 |
``` cpp
|
| 2196 |
int f(const int &);
|
| 2197 |
int f(int &);
|
| 2198 |
int g(const int &);
|
|
|
|
| 2208 |
};
|
| 2209 |
void g(const X& a, X b) {
|
| 2210 |
a.f(); // calls X::f() const
|
| 2211 |
b.f(); // calls X::f()
|
| 2212 |
}
|
| 2213 |
+
|
| 2214 |
+
int h(int (&)[]);
|
| 2215 |
+
int h(int (&)[1]);
|
| 2216 |
+
void g2() {
|
| 2217 |
+
int a[1];
|
| 2218 |
+
h(a); // calls h(int (&)[1])
|
| 2219 |
+
}
|
| 2220 |
+
```
|
| 2221 |
+
|
| 2222 |
+
— *end example*]
|
| 2223 |
+
or, if not that,
|
| 2224 |
+
- `S1` and `S2` bind the same reference type “reference to `T`” and
|
| 2225 |
+
have source types `V1` and `V2`, respectively, where the standard
|
| 2226 |
+
conversion sequence from `V1*` to `T*` is better than the standard
|
| 2227 |
+
conversion sequence from `V2*` to `T*`.
|
| 2228 |
+
\[*Example 7*:
|
| 2229 |
+
``` cpp
|
| 2230 |
+
struct Z {};
|
| 2231 |
+
|
| 2232 |
+
struct A {
|
| 2233 |
+
operator Z&();
|
| 2234 |
+
operator const Z&(); // #1
|
| 2235 |
+
};
|
| 2236 |
+
|
| 2237 |
+
struct B {
|
| 2238 |
+
operator Z();
|
| 2239 |
+
operator const Z&&(); // #2
|
| 2240 |
+
};
|
| 2241 |
+
|
| 2242 |
+
const Z& r1 = A(); // OK, uses #1
|
| 2243 |
+
const Z&& r2 = B(); // OK, uses #2
|
| 2244 |
```
|
| 2245 |
|
| 2246 |
— *end example*]
|
| 2247 |
- User-defined conversion sequence `U1` is a better conversion sequence
|
| 2248 |
than another user-defined conversion sequence `U2` if they contain the
|
| 2249 |
same user-defined conversion function or constructor or they
|
| 2250 |
initialize the same class in an aggregate initialization and in either
|
| 2251 |
case the second standard conversion sequence of `U1` is better than
|
| 2252 |
the second standard conversion sequence of `U2`.
|
| 2253 |
+
\[*Example 8*:
|
| 2254 |
``` cpp
|
| 2255 |
struct A {
|
| 2256 |
operator short();
|
| 2257 |
} a;
|
| 2258 |
int f(int);
|
|
|
|
| 2280 |
to the rank of `FP2`, and
|
| 2281 |
- `T3` is not a floating-point type, or `T3` is a floating-point type
|
| 2282 |
whose rank is not equal to the rank of `FP1`, or the floating-point
|
| 2283 |
conversion subrank [[conv.rank]] of `FP2` is greater than the
|
| 2284 |
subrank of `T3`.
|
| 2285 |
+
\[*Example 9*:
|
| 2286 |
``` cpp
|
| 2287 |
int f(std::float32_t);
|
| 2288 |
int f(std::float64_t);
|
| 2289 |
int f(long long);
|
| 2290 |
float x;
|
|
|
|
| 2301 |
of `B*` to `void*`.
|
| 2302 |
- If class `B` is derived directly or indirectly from class `A` and
|
| 2303 |
class `C` is derived directly or indirectly from `B`,
|
| 2304 |
- conversion of `C*` to `B*` is better than conversion of `C*` to
|
| 2305 |
`A*`,
|
| 2306 |
+
\[*Example 10*:
|
| 2307 |
``` cpp
|
| 2308 |
struct A {};
|
| 2309 |
struct B : public A {};
|
| 2310 |
struct C : public B {};
|
| 2311 |
C* pc;
|
|
|
|
| 2336 |
[[over.match.best]]); in all other contexts, the source types will be
|
| 2337 |
the same and the target types will be different. — *end note*]
|
| 2338 |
|
| 2339 |
## Address of an overload set <a id="over.over">[[over.over]]</a>
|
| 2340 |
|
| 2341 |
+
An expression that designates an overload set S and that appears without
|
| 2342 |
+
arguments is resolved to a function, a pointer to function, or a pointer
|
| 2343 |
+
to member function for a specific function that is chosen from a set of
|
| 2344 |
+
functions selected from S determined based on the target type required
|
| 2345 |
+
in the context (if any), as described below. The target can be
|
|
|
|
| 2346 |
|
| 2347 |
- an object or reference being initialized
|
| 2348 |
[[dcl.init]], [[dcl.init.ref]], [[dcl.init.list]],
|
| 2349 |
+
- the left side of an assignment [[expr.assign]],
|
| 2350 |
- a parameter of a function [[expr.call]],
|
| 2351 |
- a parameter of a user-defined operator [[over.oper]],
|
| 2352 |
- the return value of a function, operator function, or conversion
|
| 2353 |
[[stmt.return]],
|
| 2354 |
- an explicit type conversion
|
| 2355 |
[[expr.type.conv]], [[expr.static.cast]], [[expr.cast]], or
|
| 2356 |
+
- a constant template parameter [[temp.arg.nontype]].
|
| 2357 |
|
| 2358 |
+
If the target type contains a placeholder type, placeholder type
|
| 2359 |
+
deduction is performed [[dcl.type.auto.deduct]], and the remainder of
|
| 2360 |
+
this subclause uses the target type so deduced. The expression can be
|
| 2361 |
+
preceded by the `&` operator.
|
| 2362 |
|
| 2363 |
[*Note 1*: Any redundant set of parentheses surrounding the function
|
| 2364 |
name is ignored [[expr.prim.paren]]. — *end note*]
|
| 2365 |
|
| 2366 |
If there is no target, all non-template functions named are selected.
|
|
|
|
| 2389 |
[[temp.constr.decl]] are eliminated from the set of selected functions.
|
| 2390 |
If more than one function in the set remains, all function template
|
| 2391 |
specializations in the set are eliminated if the set also contains a
|
| 2392 |
function that is not a function template specialization. Any given
|
| 2393 |
non-template function `F0` is eliminated if the set contains a second
|
| 2394 |
+
non-template function that is more partial-ordering-constrained than
|
| 2395 |
+
`F0` [[temp.constr.order]]. Any given function template specialization
|
| 2396 |
+
`F1` is eliminated if the set contains a second function template
|
| 2397 |
+
specialization whose function template is more specialized than the
|
| 2398 |
+
function template of `F1` according to the partial ordering rules of
|
| 2399 |
+
[[temp.func.order]]. After such eliminations, if any, there shall remain
|
| 2400 |
+
exactly one selected function.
|
| 2401 |
|
| 2402 |
[*Example 1*:
|
| 2403 |
|
| 2404 |
``` cpp
|
| 2405 |
int f(double);
|
|
|
|
| 2413 |
(int (*)(int))&f; // cast expression as selector
|
| 2414 |
}
|
| 2415 |
```
|
| 2416 |
|
| 2417 |
The initialization of `pfe` is ill-formed because no `f()` with type
|
| 2418 |
+
`int(...)` has been declared, and not because of any ambiguity.
|
| 2419 |
+
|
| 2420 |
+
— *end example*]
|
| 2421 |
+
|
| 2422 |
+
[*Example 2*:
|
| 2423 |
|
| 2424 |
``` cpp
|
| 2425 |
struct X {
|
| 2426 |
int f(int);
|
| 2427 |
static int f(long);
|
|
|
|
| 2436 |
int (*p6)(long) = &(X::f); // OK
|
| 2437 |
```
|
| 2438 |
|
| 2439 |
— *end example*]
|
| 2440 |
|
| 2441 |
+
[*Example 3*:
|
| 2442 |
+
|
| 2443 |
+
``` cpp
|
| 2444 |
+
template<bool B> struct X {
|
| 2445 |
+
void f(short) requires B;
|
| 2446 |
+
void f(long);
|
| 2447 |
+
template<typename> void g(short) requires B;
|
| 2448 |
+
template<typename> void g(long);
|
| 2449 |
+
};
|
| 2450 |
+
void test() {
|
| 2451 |
+
&X<true>::f; // error: ambiguous; constraints are not considered
|
| 2452 |
+
&X<true>::g<int>; // error: ambiguous; constraints are not considered
|
| 2453 |
+
}
|
| 2454 |
+
```
|
| 2455 |
+
|
| 2456 |
+
— *end example*]
|
| 2457 |
+
|
| 2458 |
[*Note 4*: If `f` and `g` are both overload sets, the Cartesian product
|
| 2459 |
of possibilities is considered to resolve `f(&g)`, or the equivalent
|
| 2460 |
expression `f(g)`. — *end note*]
|
| 2461 |
|
| 2462 |
[*Note 5*:
|
|
|
|
| 2490 |
operator operator
|
| 2491 |
```
|
| 2492 |
|
| 2493 |
``` bnf
|
| 2494 |
%% Ed. note: character protrusion would misalign various operators.
|
| 2495 |
+
|
| 2496 |
operator: one of
|
| 2497 |
'new delete new[] delete[] co_await ( ) [ ] -> ->*'
|
| 2498 |
'~ ! + - * / % ^ &'
|
| 2499 |
'| = += -= *= /= %= ^= &='
|
| 2500 |
'|= == != < > <= >= <=> &&'
|
|
|
|
| 2549 |
|
| 2550 |
The `co_await` operator is described completely in [[expr.await]]. The
|
| 2551 |
attributes and restrictions found in the rest of [[over.oper]] do not
|
| 2552 |
apply to it unless explicitly stated in [[expr.await]].
|
| 2553 |
|
| 2554 |
+
An operator function shall have at least one function parameter or
|
| 2555 |
+
implicit object parameter whose type is a class, a reference to a class,
|
| 2556 |
+
an enumeration, or a reference to an enumeration. It is not possible to
|
| 2557 |
+
change the precedence, grouping, or number of operands of operators. The
|
| 2558 |
+
meaning of the operators `=`, (unary) `&`, and `,` (comma), predefined
|
| 2559 |
+
for each type, can be changed for specific class types by defining
|
| 2560 |
+
operator functions that implement these operators. Likewise, the meaning
|
| 2561 |
+
of the operators (unary) `&` and `,` (comma) can be changed for specific
|
| 2562 |
+
enumeration types. Operator functions are inherited in the same manner
|
| 2563 |
+
as other base class functions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2564 |
|
| 2565 |
An operator function shall be a prefix unary, binary, function call,
|
| 2566 |
subscripting, class member access, increment, or decrement operator
|
| 2567 |
function.
|
| 2568 |
|
| 2569 |
[*Note 3*: The identities among certain predefined operators applied to
|
| 2570 |
+
fundamental types (for example, `++a` ≡ `a+=1`) need not hold for
|
| 2571 |
+
operator functions. Some predefined operators, such as `+=`, require an
|
| 2572 |
+
operand to be an lvalue when applied to fundamental types; this is not
|
| 2573 |
+
required by operator functions. — *end note*]
|
| 2574 |
|
| 2575 |
An operator function cannot have default arguments [[dcl.fct.default]],
|
| 2576 |
except where explicitly stated below. Operator functions cannot have
|
| 2577 |
more or fewer parameters than the number required for the corresponding
|
| 2578 |
operator, as described in the rest of [[over.oper]].
|
| 2579 |
|
| 2580 |
+
Operators not mentioned explicitly in subclauses [[over.assign]]
|
| 2581 |
+
through [[over.inc]] act as ordinary unary and binary operators obeying
|
| 2582 |
+
the rules of [[over.unary]] or [[over.binary]].
|
| 2583 |
|
| 2584 |
### Unary operators <a id="over.unary">[[over.unary]]</a>
|
| 2585 |
|
| 2586 |
A *prefix unary operator function* is a function named `operator@` for a
|
| 2587 |
prefix *unary-operator* `@` [[expr.unary.op]] that is either a
|
|
|
|
| 2639 |
three-way comparison operator [[expr.spaceship]]. A
|
| 2640 |
*comparison operator function* is an equality operator function, a
|
| 2641 |
relational operator function, or a three-way comparison operator
|
| 2642 |
function.
|
| 2643 |
|
| 2644 |
+
#### Simple assignment <a id="over.assign">[[over.assign]]</a>
|
| 2645 |
|
| 2646 |
A *simple assignment operator function* is a binary operator function
|
| 2647 |
named `operator=`. A simple assignment operator function shall be a
|
| 2648 |
non-static member function.
|
| 2649 |
|
|
|
|
| 2971 |
R operator<=>(T, T);
|
| 2972 |
```
|
| 2973 |
|
| 2974 |
where `R` is the result type specified in [[expr.spaceship]].
|
| 2975 |
|
| 2976 |
+
For every `T`, where `T` is a pointer-to-member type, `std::meta::info`,
|
| 2977 |
+
or `std::nullptr_t`, there exist candidate operator functions of the
|
| 2978 |
+
form
|
| 2979 |
|
| 2980 |
``` cpp
|
| 2981 |
bool operator==(T, T);
|
| 2982 |
bool operator!=(T, T);
|
| 2983 |
```
|
|
|
|
| 3079 |
|
| 3080 |
## User-defined literals <a id="over.literal">[[over.literal]]</a>
|
| 3081 |
|
| 3082 |
``` bnf
|
| 3083 |
literal-operator-id:
|
| 3084 |
+
operator unevaluated-string identifier
|
| 3085 |
operator user-defined-string-literal
|
| 3086 |
```
|
| 3087 |
|
| 3088 |
+
The *user-defined-string-literal* in a *literal-operator-id* shall have
|
| 3089 |
+
no *encoding-prefix*. The *unevaluated-string* or
|
| 3090 |
+
*user-defined-string-literal* shall be empty. The *ud-suffix* of the
|
| 3091 |
+
*user-defined-string-literal* or the *identifier* in a
|
| 3092 |
+
*literal-operator-id* is called a *literal suffix identifier*. The first
|
| 3093 |
+
form of *literal-operator-id* is deprecated [[depr.lit]]. Some literal
|
| 3094 |
+
suffix identifiers are reserved for future standardization; see
|
| 3095 |
[[usrlit.suffix]]. A declaration whose *literal-operator-id* uses such a
|
| 3096 |
literal suffix identifier is ill-formed, no diagnostic required.
|
| 3097 |
|
| 3098 |
A declaration whose *declarator-id* is a *literal-operator-id* shall
|
| 3099 |
declare a function or function template that belongs to a namespace (it
|
|
|
|
| 3128 |
A *raw literal operator* is a literal operator with a single parameter
|
| 3129 |
whose type is `const char*`.
|
| 3130 |
|
| 3131 |
A *numeric literal operator template* is a literal operator template
|
| 3132 |
whose *template-parameter-list* has a single *template-parameter* that
|
| 3133 |
+
is a constant template parameter pack [[temp.variadic]] with element
|
| 3134 |
type `char`. A *string literal operator template* is a literal operator
|
| 3135 |
+
template whose *template-parameter-list* comprises a single
|
| 3136 |
+
*parameter-declaration* that declares a constant template parameter of
|
| 3137 |
+
class type. The declaration of a literal operator template shall have an
|
| 3138 |
+
empty *parameter-declaration-clause* and shall declare either a numeric
|
| 3139 |
+
literal operator template or a string literal operator template.
|
| 3140 |
|
| 3141 |
Literal operators and literal operator templates shall not have C
|
| 3142 |
language linkage.
|
| 3143 |
|
| 3144 |
[*Note 1*: Literal operators and literal operator templates are usually
|
|
|
|
| 3213 |
[dcl.init]: dcl.md#dcl.init
|
| 3214 |
[dcl.init.aggr]: dcl.md#dcl.init.aggr
|
| 3215 |
[dcl.init.list]: dcl.md#dcl.init.list
|
| 3216 |
[dcl.init.ref]: dcl.md#dcl.init.ref
|
| 3217 |
[dcl.init.string]: dcl.md#dcl.init.string
|
| 3218 |
+
[dcl.type.auto.deduct]: dcl.md#dcl.type.auto.deduct
|
| 3219 |
[dcl.type.class.deduct]: dcl.md#dcl.type.class.deduct
|
| 3220 |
[dcl.type.simple]: dcl.md#dcl.type.simple
|
| 3221 |
[depr.lit]: future.md#depr.lit
|
| 3222 |
[expr.arith.conv]: expr.md#expr.arith.conv
|
| 3223 |
+
[expr.assign]: expr.md#expr.assign
|
| 3224 |
[expr.await]: expr.md#expr.await
|
| 3225 |
[expr.call]: expr.md#expr.call
|
| 3226 |
[expr.cast]: expr.md#expr.cast
|
| 3227 |
[expr.compound]: expr.md#expr.compound
|
| 3228 |
[expr.cond]: expr.md#expr.cond
|
| 3229 |
[expr.eq]: expr.md#expr.eq
|
| 3230 |
[expr.mptr.oper]: expr.md#expr.mptr.oper
|
| 3231 |
[expr.pre.incr]: expr.md#expr.pre.incr
|
| 3232 |
[expr.prim.paren]: expr.md#expr.prim.paren
|
| 3233 |
+
[expr.prim.splice]: expr.md#expr.prim.splice
|
| 3234 |
[expr.prim.this]: expr.md#expr.prim.this
|
| 3235 |
[expr.rel]: expr.md#expr.rel
|
| 3236 |
[expr.spaceship]: expr.md#expr.spaceship
|
| 3237 |
[expr.static.cast]: expr.md#expr.static.cast
|
| 3238 |
[expr.sub]: expr.md#expr.sub
|
| 3239 |
[expr.type.conv]: expr.md#expr.type.conv
|
| 3240 |
[expr.unary.op]: expr.md#expr.unary.op
|
| 3241 |
[lex.ext]: lex.md#lex.ext
|
| 3242 |
[namespace.udecl]: dcl.md#namespace.udecl
|
| 3243 |
[over]: #over
|
| 3244 |
+
[over.assign]: #over.assign
|
| 3245 |
[over.best.ics]: #over.best.ics
|
| 3246 |
[over.best.ics.general]: #over.best.ics.general
|
| 3247 |
[over.binary]: #over.binary
|
| 3248 |
[over.binary.general]: #over.binary.general
|
| 3249 |
[over.built]: #over.built
|