From Jason Turner

[over]

Large diff (112.0 KB) - rendering may be slow on some devices

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpzx146f7a/{from.md → to.md} +645 -721
tmp/tmpzx146f7a/{from.md → to.md} RENAMED
@@ -1,21 +1,19 @@
1
  # Overloading <a id="over">[[over]]</a>
2
 
3
  ## Preamble <a id="over.pre">[[over.pre]]</a>
4
 
5
- When two or more different declarations are specified for a single name
6
- in the same scope, that name is said to be *overloaded*, and the
7
- declarations are called *overloaded declarations*. Only function and
8
- function template declarations can be overloaded; variable and type
9
- declarations cannot be overloaded.
10
 
11
- When a function name is used in a call, which function declaration is
12
- being referenced and the validity of the call are determined by
13
- comparing the types of the arguments at the point of use with the types
14
- of the parameters in the declarations that are visible at the point of
15
- use. This function selection process is called *overload resolution* and
16
- is defined in  [[over.match]].
17
 
18
  [*Example 1*:
19
 
20
  ``` cpp
21
  double abs(double);
@@ -25,293 +23,22 @@ abs(1); // calls abs(int);
25
  abs(1.0); // calls abs(double);
26
  ```
27
 
28
  — *end example*]
29
 
30
- ## Overloadable declarations <a id="over.load">[[over.load]]</a>
31
-
32
- Not all function declarations can be overloaded. Those that cannot be
33
- overloaded are specified here. A program is ill-formed if it contains
34
- two such non-overloadable declarations in the same scope.
35
-
36
- [*Note 1*: This restriction applies to explicit declarations in a
37
- scope, and between such declarations and declarations made through a
38
- *using-declaration* [[namespace.udecl]]. It does not apply to sets of
39
- functions fabricated as a result of name lookup (e.g., because of
40
- *using-directive*s) or overload resolution (e.g., for operator
41
- functions). — *end note*]
42
-
43
- Certain function declarations cannot be overloaded:
44
-
45
- - Function declarations that differ only in the return type, the
46
- exception specification [[except.spec]], or both cannot be overloaded.
47
- - Member function declarations with the same name, the same
48
- parameter-type-list [[dcl.fct]], and the same trailing
49
- *requires-clause* (if any) cannot be overloaded if any of them is a
50
- `static` member function declaration [[class.static]]. Likewise,
51
- member function template declarations with the same name, the same
52
- parameter-type-list, the same trailing *requires-clause* (if any), and
53
- the same *template-head* cannot be overloaded if any of them is a
54
- `static` member function template declaration. The types of the
55
- implicit object parameters constructed for the member functions for
56
- the purpose of overload resolution [[over.match.funcs]] are not
57
- considered when comparing parameter-type-lists for enforcement of this
58
- rule. In contrast, if there is no `static` member function declaration
59
- among a set of member function declarations with the same name, the
60
- same parameter-type-list, and the same trailing *requires-clause* (if
61
- any), then these member function declarations can be overloaded if
62
- they differ in the type of their implicit object parameter.
63
- \[*Example 1*:
64
- The following illustrates this distinction:
65
- ``` cpp
66
- class X {
67
- static void f();
68
- void f(); // error
69
- void f() const; // error
70
- void f() const volatile; // error
71
- void g();
72
- void g() const; // OK: no static g
73
- void g() const volatile; // OK: no static g
74
- };
75
- ```
76
-
77
- — *end example*]
78
- - Member function declarations with the same name, the same
79
- parameter-type-list [[dcl.fct]], and the same trailing
80
- *requires-clause* (if any), as well as member function template
81
- declarations with the same name, the same parameter-type-list, the
82
- same trailing *requires-clause* (if any), and the same
83
- *template-head*, cannot be overloaded if any of them, but not all,
84
- have a *ref-qualifier* [[dcl.fct]].
85
- \[*Example 2*:
86
- ``` cpp
87
- class Y {
88
- void h() &;
89
- void h() const &; // OK
90
- void h() &&; // OK, all declarations have a ref-qualifier
91
- void i() &;
92
- void i() const; // error: prior declaration of i has a ref-qualifier
93
- };
94
- ```
95
-
96
- — *end example*]
97
-
98
- [*Note 2*:
99
-
100
- As specified in  [[dcl.fct]], function declarations that have equivalent
101
- parameter declarations and *requires-clause*s, if any
102
- [[temp.constr.decl]], declare the same function and therefore cannot be
103
- overloaded:
104
-
105
- - Parameter declarations that differ only in the use of equivalent
106
- typedef “types” are equivalent. A `typedef` is not a separate type,
107
- but only a synonym for another type [[dcl.typedef]].
108
- \[*Example 3*:
109
- ``` cpp
110
- typedef int Int;
111
-
112
- void f(int i);
113
- void f(Int i); // OK: redeclaration of f(int)
114
- void f(int i) { ... }
115
- void f(Int i) { ... } // error: redefinition of f(int)
116
- ```
117
-
118
- — *end example*]
119
- Enumerations, on the other hand, are distinct types and can be used to
120
- distinguish overloaded function declarations.
121
- \[*Example 4*:
122
- ``` cpp
123
- enum E { a };
124
-
125
- void f(int i) { ... }
126
- void f(E i) { ... }
127
- ```
128
-
129
- — *end example*]
130
- - Parameter declarations that differ only in a pointer `*` versus an
131
- array `[]` are equivalent. That is, the array declaration is adjusted
132
- to become a pointer declaration [[dcl.fct]]. Only the second and
133
- subsequent array dimensions are significant in parameter types
134
- [[dcl.array]].
135
- \[*Example 5*:
136
- ``` cpp
137
- int f(char*);
138
- int f(char[]); // same as f(char*);
139
- int f(char[7]); // same as f(char*);
140
- int f(char[9]); // same as f(char*);
141
-
142
- int g(char(*)[10]);
143
- int g(char[5][10]); // same as g(char(*)[10]);
144
- int g(char[7][10]); // same as g(char(*)[10]);
145
- int g(char(*)[20]); // different from g(char(*)[10]);
146
- ```
147
-
148
- — *end example*]
149
- - Parameter declarations that differ only in that one is a function type
150
- and the other is a pointer to the same function type are equivalent.
151
- That is, the function type is adjusted to become a pointer to function
152
- type [[dcl.fct]].
153
- \[*Example 6*:
154
- ``` cpp
155
- void h(int());
156
- void h(int (*)()); // redeclaration of h(int())
157
- void h(int x()) { } // definition of h(int())
158
- void h(int (*x)()) { } // error: redefinition of h(int())
159
- ```
160
-
161
- — *end example*]
162
- - Parameter declarations that differ only in the presence or absence of
163
- `const` and/or `volatile` are equivalent. That is, the `const` and
164
- `volatile` type-specifiers for each parameter type are ignored when
165
- determining which function is being declared, defined, or called.
166
- \[*Example 7*:
167
- ``` cpp
168
- typedef const int cInt;
169
-
170
- int f (int);
171
- int f (const int); // redeclaration of f(int)
172
- int f (int) { ... } // definition of f(int)
173
- int f (cInt) { ... } // error: redefinition of f(int)
174
- ```
175
-
176
- — *end example*]
177
- Only the `const` and `volatile` type-specifiers at the outermost level
178
- of the parameter type specification are ignored in this fashion;
179
- `const` and `volatile` type-specifiers buried within a parameter type
180
- specification are significant and can be used to distinguish
181
- overloaded function declarations.[^1] In particular, for any type `T`,
182
- “pointer to `T`”, “pointer to `const` `T`”, and “pointer to `volatile`
183
- `T`” are considered distinct parameter types, as are “reference to
184
- `T`”, “reference to `const` `T`”, and “reference to `volatile` `T`”.
185
- - Two parameter declarations that differ only in their default arguments
186
- are equivalent.
187
- \[*Example 8*:
188
- Consider the following:
189
- ``` cpp
190
- void f (int i, int j);
191
- void f (int i, int j = 99); // OK: redeclaration of f(int, int)
192
- void f (int i = 88, int j); // OK: redeclaration of f(int, int)
193
- void f (); // OK: overloaded declaration of f
194
-
195
- void prog () {
196
- f (1, 2); // OK: call f(int, int)
197
- f (1); // OK: call f(int, int)
198
- f (); // error: f(int, int) or f()?
199
- }
200
- ```
201
-
202
- — *end example*]
203
-
204
- — *end note*]
205
-
206
- ## Declaration matching <a id="over.dcl">[[over.dcl]]</a>
207
-
208
- Two function declarations of the same name refer to the same function if
209
- they are in the same scope and have equivalent parameter declarations
210
- [[over.load]] and equivalent [[temp.over.link]] trailing
211
- *requires-clause*s, if any [[dcl.decl]].
212
-
213
- [*Note 1*:
214
-
215
- Since a *constraint-expression* is an unevaluated operand, equivalence
216
- compares the expressions without evaluating them.
217
-
218
- [*Example 1*:
219
-
220
- ``` cpp
221
- template<int I> concept C = true;
222
- template<typename T> struct A {
223
- void f() requires C<42>; // #1
224
- void f() requires true; // OK, different functions
225
- };
226
- ```
227
-
228
- — *end example*]
229
-
230
- — *end note*]
231
-
232
- A function member of a derived class is *not* in the same scope as a
233
- function member of the same name in a base class.
234
-
235
- [*Example 2*:
236
-
237
- ``` cpp
238
- struct B {
239
- int f(int);
240
- };
241
-
242
- struct D : B {
243
- int f(const char*);
244
- };
245
- ```
246
-
247
- Here `D::f(const char*)` hides `B::f(int)` rather than overloading it.
248
-
249
- ``` cpp
250
- void h(D* pd) {
251
- pd->f(1); // error:
252
- // D::f(const char*) hides B::f(int)
253
- pd->B::f(1); // OK
254
- pd->f("Ben"); // OK, calls D::f
255
- }
256
- ```
257
-
258
- — *end example*]
259
-
260
- A locally declared function is not in the same scope as a function in a
261
- containing scope.
262
-
263
- [*Example 3*:
264
-
265
- ``` cpp
266
- void f(const char*);
267
- void g() {
268
- extern void f(int);
269
- f("asdf"); // error: f(int) hides f(const char*)
270
- // so there is no f(const char*) in this scope
271
- }
272
-
273
- void caller () {
274
- extern void callee(int, int);
275
- {
276
- extern void callee(int); // hides callee(int, int)
277
- callee(88, 99); // error: only callee(int) in scope
278
- }
279
- }
280
- ```
281
-
282
- — *end example*]
283
-
284
- Different versions of an overloaded member function can be given
285
- different access rules.
286
-
287
- [*Example 4*:
288
-
289
- ``` cpp
290
- class buffer {
291
- private:
292
- char* p;
293
- int size;
294
- protected:
295
- buffer(int s, char* store) { size = s; p = store; }
296
- public:
297
- buffer(int s) { p = new char[size = s]; }
298
- };
299
- ```
300
-
301
- — *end example*]
302
-
303
  ## Overload resolution <a id="over.match">[[over.match]]</a>
304
 
 
 
305
  Overload resolution is a mechanism for selecting the best function to
306
  call given a list of expressions that are to be the arguments of the
307
  call and a set of *candidate functions* that can be called based on the
308
  context of the call. The selection criteria for the best function are
309
  the number of arguments, how well the arguments match the
310
  parameter-type-list of the candidate function, how well (for non-static
311
- member functions) the object matches the implicit object parameter, and
312
- certain other properties of the candidate function.
313
 
314
  [*Note 1*: The function selected by overload resolution is not
315
  guaranteed to be appropriate for the context. Other restrictions, such
316
  as the accessibility of the function, can make its use in the calling
317
  context ill-formed. — *end note*]
@@ -361,31 +88,36 @@ resolution succeeds and the selected candidate is either not a function
361
  [[over.built]], or is a function that is not deleted and is accessible
362
  from the context in which overload resolution was performed.
363
 
364
  ### Candidate functions and argument lists <a id="over.match.funcs">[[over.match.funcs]]</a>
365
 
 
 
366
  The subclauses of  [[over.match.funcs]] describe the set of candidate
367
  functions and the argument list submitted to overload resolution in each
368
  context in which overload resolution is used. The source transformations
369
  and constructions defined in these subclauses are only for the purpose
370
  of describing the overload resolution process. An implementation is not
371
  required to use such transformations and constructions.
372
 
373
  The set of candidate functions can contain both member and non-member
374
- functions to be resolved against the same argument list. So that
375
- argument and parameter lists are comparable within this heterogeneous
376
- set, a member function is considered to have an extra first parameter,
377
- called the *implicit object parameter*, which represents the object for
378
- which the member function has been called. For the purposes of overload
379
- resolution, both static and non-static member functions have an implicit
380
- object parameter, but constructors do not.
 
 
 
381
 
382
  Similarly, when appropriate, the context can construct an argument list
383
  that contains an *implied object argument* as the first argument in the
384
  list to denote the object to be operated on.
385
 
386
- For non-static member functions, the type of the implicit object
387
  parameter is
388
 
389
  - “lvalue reference to cv `X`” for functions declared without a
390
  *ref-qualifier* or with the `&` *ref-qualifier*
391
  - “rvalue reference to cv `X`” for functions declared with the `&&`
@@ -393,44 +125,46 @@ parameter is
393
 
394
  where `X` is the class of which the function is a member and cv is the
395
  cv-qualification on the member function declaration.
396
 
397
  [*Example 1*: For a `const` member function of class `X`, the extra
398
- parameter is assumed to have type “reference to
399
  `const X`”. — *end example*]
400
 
401
- For conversion functions, the function is considered to be a member of
402
- the class of the implied object argument for the purpose of defining the
403
- type of the implicit object parameter. For non-conversion functions
404
- introduced by a *using-declaration* into a derived class, the function
405
- is considered to be a member of the derived class for the purpose of
406
- defining the type of the implicit object parameter. For static member
407
- functions, the implicit object parameter is considered to match any
408
- object (since if the function is selected, the object is discarded).
 
 
409
 
410
  [*Note 1*: No actual type is established for the implicit object
411
  parameter of a static member function, and no attempt will be made to
412
  determine a conversion sequence for that parameter
413
  [[over.match.best]]. — *end note*]
414
 
415
  During overload resolution, the implied object argument is
416
  indistinguishable from other arguments. The implicit object parameter,
417
  however, retains its identity since no user-defined conversions can be
418
- applied to achieve a type match with it. For non-static member functions
419
- declared without a *ref-qualifier*, even if the implicit object
420
- parameter is not const-qualified, an rvalue can be bound to the
421
  parameter as long as in all other respects the argument can be converted
422
  to the type of the implicit object parameter.
423
 
424
  [*Note 2*: The fact that such an argument is an rvalue does not affect
425
  the ranking of implicit conversion sequences
426
  [[over.ics.rank]]. — *end note*]
427
 
428
  Because other than in list-initialization only one user-defined
429
  conversion is allowed in an implicit conversion sequence, special rules
430
- apply when selecting the best user-defined conversion (
431
- [[over.match.best]], [[over.best.ics]]).
432
 
433
  [*Example 2*:
434
 
435
  ``` cpp
436
  class T {
@@ -445,33 +179,57 @@ public:
445
  T a = 1; // error: no viable conversion (T(C(1)) not considered)
446
  ```
447
 
448
  — *end example*]
449
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450
  In each case where a candidate is a function template, candidate
451
  function template specializations are generated using template argument
452
- deduction ([[temp.over]], [[temp.deduct]]). If a constructor template
453
- or conversion function template has an *explicit-specifier* whose
454
  *constant-expression* is value-dependent [[temp.dep]], template argument
455
- deduction is performed first and then, if the context requires a
456
- candidate that is not explicit and the generated specialization is
457
  explicit [[dcl.fct.spec]], it will be removed from the candidate set.
458
  Those candidates are then handled as candidate functions in the usual
459
- way.[^2] A given name can refer to one or more function templates and
460
- also to a set of non-template functions. In such a case, the candidate
461
- functions generated from each function template are combined with the
462
- set of non-template candidate functions.
463
 
464
- A defaulted move special member function ([[class.copy.ctor]],
465
- [[class.copy.assign]]) that is defined as deleted is excluded from the
466
- set of candidate functions in all contexts. A constructor inherited from
467
- class type `C` [[class.inhctor.init]] that has a first parameter of type
468
- “reference to *cv1* `P`” (including such a constructor instantiated from
469
- a template) is excluded from the set of candidate functions when
470
- constructing an object of type *cv2* `D` if the argument list has
471
- exactly one argument and `C` is reference-related to `P` and `P` is
472
- reference-related to `D`.
 
 
 
 
 
473
 
474
  [*Example 3*:
475
 
476
  ``` cpp
477
  struct A {
@@ -494,10 +252,12 @@ B b3 = C(); // calls #4
494
 
495
  — *end example*]
496
 
497
  #### Function call syntax <a id="over.match.call">[[over.match.call]]</a>
498
 
 
 
499
  In a function call [[expr.call]]
500
 
501
  ``` bnf
502
  postfix-expression '(' expression-listₒₚₜ ')'
503
  ```
@@ -507,24 +267,27 @@ template, overload resolution is applied as specified in
507
  [[over.call.func]]. If the *postfix-expression* denotes an object of
508
  class type, overload resolution is applied as specified in
509
  [[over.call.object]].
510
 
511
  If the *postfix-expression* is the address of an overload set, overload
512
- resolution is applied using that set as described above. If the function
513
- selected by overload resolution is a non-static member function, the
514
- program is ill-formed.
515
 
516
- [*Note 1*: The resolution of the address of an overload set in other
 
 
 
 
 
 
517
  contexts is described in [[over.over]]. — *end note*]
518
 
519
  ##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
520
 
521
  Of interest in  [[over.call.func]] are only those function calls in
522
- which the *postfix-expression* ultimately contains a name that denotes
523
- one or more functions that might be called. Such a *postfix-expression*,
524
- perhaps nested arbitrarily deep in parentheses, has one of the following
525
- forms:
526
 
527
  ``` bnf
528
  postfix-expression:
529
  postfix-expression '.' id-expression
530
  postfix-expression '->' id-expression
@@ -532,52 +295,94 @@ postfix-expression:
532
  ```
533
 
534
  These represent two syntactic subcategories of function calls: qualified
535
  function calls and unqualified function calls.
536
 
537
- In qualified function calls, the name to be resolved is an
538
- *id-expression* and is preceded by an `->` or `.` operator. Since the
539
- construct `A->B` is generally equivalent to `(*A).B`, the rest of
540
- [[over]] assumes, without loss of generality, that all member function
541
- calls have been normalized to the form that uses an object and the `.`
542
- operator. Furthermore, [[over]] assumes that the *postfix-expression*
543
- that is the left operand of the `.` operator has type “cv `T`” where `T`
544
- denotes a class.[^3] Under this assumption, the *id-expression* in the
545
- call is looked up as a member function of `T` following the rules for
546
- looking up names in classes [[class.member.lookup]]. The function
547
- declarations found by that lookup constitute the set of candidate
548
- functions. The argument list is the *expression-list* in the call
549
- augmented by the addition of the left operand of the `.` operator in the
550
- normalized member function call as the implied object argument
551
- [[over.match.funcs]].
552
-
553
- In unqualified function calls, the name is not qualified by an `->` or
554
- `.` operator and has the more general form of a *primary-expression*.
555
- The name is looked up in the context of the function call following the
556
- normal rules for name lookup in expressions [[basic.lookup]]. The
557
- function declarations found by that lookup constitute the set of
558
- candidate functions. Because of the rules for name lookup, the set of
559
- candidate functions consists (1) entirely of non-member functions or (2)
560
- entirely of member functions of some class `T`. In case (1), the
561
- argument list is the same as the *expression-list* in the call. In case
562
- (2), the argument list is the *expression-list* in the call augmented by
563
- the addition of an implied object argument as in a qualified function
564
- call. If the keyword `this` [[class.this]] is in scope and refers to
565
- class `T`, or a derived class of `T`, then the implied object argument
566
- is `(*this)`. If the keyword `this` is not in scope or refers to another
567
- class, then a contrived object of type `T` becomes the implied object
568
- argument.[^4] If the argument list is augmented by a contrived object
569
- and overload resolution selects one of the non-static member functions
570
- of `T`, the call is ill-formed.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
571
 
572
  ##### Call to object of class type <a id="over.call.object">[[over.call.object]]</a>
573
 
574
  If the *postfix-expression* `E` in the function call syntax evaluates to
575
  a class object of type “cv `T`”, then the set of candidate functions
576
  includes at least the function call operators of `T`. The function call
577
- operators of `T` are obtained by ordinary lookup of the name
578
- `operator()` in the context of `(E).operator()`.
579
 
580
  In addition, for each non-explicit conversion function declared in `T`
581
  of the form
582
 
583
  ``` bnf
@@ -599,27 +404,23 @@ returning `R`”, a *surrogate call function* with the unique name
599
 
600
  is also considered as a candidate function. Similarly, surrogate call
601
  functions are added to the set of candidate functions for each
602
  non-explicit conversion function declared in a base class of `T`
603
  provided the function is not hidden within `T` by another intervening
604
- declaration.[^5]
605
 
606
  The argument list submitted to overload resolution consists of the
607
  argument expressions present in the function call syntax preceded by the
608
  implied object argument `(E)`.
609
 
610
- [*Note 2*: When comparing the call against the function call operators,
611
- the implied object argument is compared against the implicit object
612
- parameter of the function call operator. When comparing the call against
613
- a surrogate call function, the implied object argument is compared
614
- against the first parameter of the surrogate call function. The
615
- conversion function from which the surrogate call function was derived
616
- will be used in the conversion sequence for that parameter since it
617
- converts the implied object argument to the appropriate function pointer
618
- or reference required by that first parameter. — *end note*]
619
 
620
- [*Example 1*:
621
 
622
  ``` cpp
623
  int f1(int);
624
  int f2(float);
625
  typedef int (*fp1)(int);
@@ -665,11 +466,11 @@ void f() {
665
  ```
666
 
667
  — *end example*]
668
 
669
  If either operand has a type that is a class or an enumeration, a
670
- user-defined operator function might be declared that implements this
671
  operator or a user-defined conversion can be necessary to convert the
672
  operand to a type that is appropriate for a built-in operator. In this
673
  case, overload resolution is used to determine which operator function
674
  or built-in operator is to be invoked to implement the operator.
675
  Therefore, the operator notation is first transformed to the equivalent
@@ -695,21 +496,21 @@ binary operator `@` with a left operand of type *cv1* `T1` and a right
695
  operand of type *cv2* `T2`, four sets of candidate functions, designated
696
  *member candidates*, *non-member candidates*, *built-in candidates*, and
697
  *rewritten candidates*, are constructed as follows:
698
 
699
  - If `T1` is a complete class type or a class currently being defined,
700
- the set of member candidates is the result of the qualified lookup of
701
- `T1::operator@` [[over.call.func]]; otherwise, the set of member
702
- candidates is empty.
703
- - The set of non-member candidates is the result of the unqualified
704
- lookup of `operator@` in the context of the expression according to
705
- the usual rules for name lookup in unqualified function calls
706
- [[basic.lookup.argdep]] except that all member functions are ignored.
707
- However, if no operand has a class type, only those non-member
708
- functions in the lookup set that have a first parameter of type `T1`
709
- or “reference to cv `T1`”, when `T1` is an enumeration type, or (if
710
- there is a right operand) a second parameter of type `T2` or
711
  “reference to cv `T2`”, when `T2` is an enumeration type, are
712
  candidate functions.
713
  - For the operator `,`, the unary operator `&`, or the operator `->`,
714
  the built-in candidates set is empty. For all other operators, the
715
  built-in candidates include all of the candidate operator functions
@@ -717,32 +518,76 @@ operand of type *cv2* `T2`, four sets of candidate functions, designated
717
  - have the same operator name, and
718
  - accept the same number of operands, and
719
  - accept operand types to which the given operand or operands can be
720
  converted according to [[over.best.ics]], and
721
  - do not have the same parameter-type-list as any non-member candidate
722
- that is not a function template specialization.
 
723
  - The rewritten candidate set is determined as follows:
724
  - For the relational [[expr.rel]] operators, the rewritten candidates
725
  include all non-rewritten candidates for the expression `x <=> y`.
726
  - For the relational [[expr.rel]] and three-way comparison
727
  [[expr.spaceship]] operators, the rewritten candidates also include
728
  a synthesized candidate, with the order of the two parameters
729
  reversed, for each non-rewritten candidate for the expression
730
  `y <=> x`.
731
  - For the `!=` operator [[expr.eq]], the rewritten candidates include
732
- all non-rewritten candidates for the expression `x == y`.
 
733
  - For the equality operators, the rewritten candidates also include a
734
  synthesized candidate, with the order of the two parameters
735
  reversed, for each non-rewritten candidate for the expression
736
- `y == x`.
737
  - For all other operators, the rewritten candidate set is empty.
738
 
739
  \[*Note 2*: A candidate synthesized from a member candidate has its
740
- implicit object parameter as the second parameter, thus implicit
741
- conversions are considered for the first, but not for the second,
742
  parameter. — *end note*]
743
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
744
  For the built-in assignment operators, conversions of the left operand
745
  are restricted as follows:
746
 
747
  - no temporaries are introduced to hold the left operand, and
748
  - no user-defined conversions are applied to the left operand to achieve
@@ -755,13 +600,13 @@ The set of candidate functions for overload resolution for some operator
755
  the built-in candidates, and the rewritten candidates for that operator
756
  `@`.
757
 
758
  The argument list contains all of the operands of the operator. The best
759
  function from the set of candidate functions is selected according to 
760
- [[over.match.viable]] and  [[over.match.best]].[^6]
761
 
762
- [*Example 2*:
763
 
764
  ``` cpp
765
  struct A {
766
  operator int();
767
  };
@@ -799,11 +644,11 @@ of the selected operation function, except that the second standard
799
  conversion sequence of a user-defined conversion sequence
800
  [[over.ics.user]] is not applied. Then the operator is treated as the
801
  corresponding built-in operator and interpreted according to
802
  [[expr.compound]].
803
 
804
- [*Example 3*:
805
 
806
  ``` cpp
807
  struct X {
808
  operator double();
809
  };
@@ -819,11 +664,11 @@ int *b = Y() + X(); // error: pointer arithmetic requires integral o
819
  — *end example*]
820
 
821
  The second operand of operator `->` is ignored in selecting an
822
  `operator->` function, and is not an argument when the `operator->`
823
  function is called. When `operator->` returns, the operator `->` is
824
- applied to the value returned, with the original second operand.[^7]
825
 
826
  If the operator is the operator `,`, the unary operator `&`, or the
827
  operator `->`, and there are no viable functions, then the operator is
828
  assumed to be the built-in operator and interpreted according to
829
  [[expr.compound]].
@@ -845,11 +690,11 @@ struct B {
845
 
846
  A a;
847
 
848
  void B::f() {
849
  operator+ (a,a); // error: global operator hidden by member
850
- a + a; // OK: calls global operator+
851
  }
852
  ```
853
 
854
  — *end note*]
855
 
@@ -883,90 +728,75 @@ Assuming that “*cv1* `T`” is the type of the object being initialized,
883
  with `T` a class type, the candidate functions are selected as follows:
884
 
885
  - The converting constructors [[class.conv.ctor]] of `T` are candidate
886
  functions.
887
  - When the type of the initializer expression is a class type “cv `S`”,
888
- the non-explicit conversion functions of `S` and its base classes are
889
- considered. When initializing a temporary object [[class.mem]] to be
890
- bound to the first parameter of a constructor where the parameter is
891
- of type “reference to *cv2* `T`” and the constructor is called with a
892
- single argument in the context of direct-initialization of an object
893
- of type “*cv3* `T`”, explicit conversion functions are also
894
- considered. Those that are not hidden within `S` and yield a type
895
- whose cv-unqualified version is the same type as `T` or is a derived
896
- class thereof are candidate functions. A call to a conversion function
897
- returning “reference to `X`” is a glvalue of type `X`, and such a
898
- conversion function is therefore considered to yield `X` for this
899
- process of selecting candidate functions.
900
 
901
  In both cases, the argument list has one argument, which is the
902
  initializer expression.
903
 
904
  [*Note 2*: This argument will be compared against the first parameter
905
- of the constructors and against the implicit object parameter of the
906
- conversion functions. — *end note*]
907
 
908
  #### Initialization by conversion function <a id="over.match.conv">[[over.match.conv]]</a>
909
 
910
  Under the conditions specified in  [[dcl.init]], as part of an
911
  initialization of an object of non-class type, a conversion function can
912
  be invoked to convert an initializer expression of class type to the
913
  type of the object being initialized. Overload resolution is used to
914
- select the conversion function to be invoked. Assuming that “*cv1* `T`”
915
- is the type of the object being initialized, and “cv `S`” is the type of
916
- the initializer expression, with `S` a class type, the candidate
917
- functions are selected as follows:
918
 
919
- - The conversion functions of `S` and its base classes are considered.
920
- Those non-explicit conversion functions that are not hidden within `S`
921
- and yield type `T` or a type that can be converted to type `T` via a
922
- standard conversion sequence [[over.ics.scs]] are candidate functions.
923
- For direct-initialization, those explicit conversion functions that
924
- are not hidden within `S` and yield type `T` or a type that can be
925
- converted to type `T` with a qualification conversion [[conv.qual]]
926
- are also candidate functions. Conversion functions that return a
927
- cv-qualified type are considered to yield the cv-unqualified version
928
- of that type for this process of selecting candidate functions. A call
929
- to a conversion function returning “reference to `X`” is a glvalue of
930
- type `X`, and such a conversion function is therefore considered to
931
- yield `X` for this process of selecting candidate functions.
932
 
933
  The argument list has one argument, which is the initializer expression.
934
 
935
- [*Note 1*: This argument will be compared against the implicit object
936
- parameter of the conversion functions. — *end note*]
937
 
938
  #### Initialization by conversion function for direct reference binding <a id="over.match.ref">[[over.match.ref]]</a>
939
 
940
  Under the conditions specified in  [[dcl.init.ref]], a reference can be
941
  bound directly to the result of applying a conversion function to an
942
  initializer expression. Overload resolution is used to select the
943
  conversion function to be invoked. Assuming that “reference to *cv1*
944
- `T`” is the type of the reference being initialized, and “cv `S`” is the
945
- type of the initializer expression, with `S` a class type, the candidate
946
  functions are selected as follows:
947
 
948
- - The conversion functions of `S` and its base classes are considered.
949
- Those non-explicit conversion functions that are not hidden within `S`
950
- and yield type “lvalue reference to *cv2* `T2`” (when initializing an
951
- lvalue reference or an rvalue reference to function) or “*cv2* `T2`”
952
- or rvalue reference to *cv2* `T2`” (when initializing an rvalue
953
- reference or an lvalue reference to function), where “*cv1* `T`” is
954
- reference-compatible [[dcl.init.ref]] with “*cv2* `T2`”, are candidate
955
- functions. For direct-initialization, those explicit conversion
956
- functions that are not hidden within `S` and yield type “lvalue
957
- reference to *cv2* `T2`” (when initializing an lvalue reference or an
958
- rvalue reference to function) or “rvalue reference to *cv2* `T2`
959
- (when initializing an rvalue reference or an lvalue reference to
960
- function), where `T2` is the same type as `T` or can be converted to
961
- type `T` with a qualification conversion [[conv.qual]], are also
962
- candidate functions.
963
 
964
  The argument list has one argument, which is the initializer expression.
965
 
966
- [*Note 1*: This argument will be compared against the implicit object
967
- parameter of the conversion functions. — *end note*]
968
 
969
  #### Initialization by list-initialization <a id="over.match.list">[[over.match.list]]</a>
970
 
971
  When objects of non-aggregate class type `T` are list-initialized such
972
  that [[dcl.init.list]] specifies that overload resolution is performed
@@ -985,15 +815,15 @@ resolution selects the constructor in two phases:
985
  consists of the elements of the initializer list.
986
 
987
  In copy-list-initialization, if an explicit constructor is chosen, the
988
  initialization is ill-formed.
989
 
990
- [*Note 1*: This differs from other situations ([[over.match.ctor]],
991
- [[over.match.copy]]), where only converting constructors are considered
992
- for copy-initialization. This restriction only applies if this
993
- initialization is part of the final result of overload
994
- resolution. — *end note*]
995
 
996
  #### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
997
 
998
  When resolving a placeholder for a deduced class type
999
  [[dcl.type.class.deduct]] where the *template-name* names a primary
@@ -1032,35 +862,112 @@ the elements of the *initializer-list* or *designated-initializer-list*
1032
  of the *braced-init-list*, or of the *expression-list*. For each xᵢ, let
1033
  eᵢ be the corresponding aggregate element of `C` or of one of its
1034
  (possibly recursive) subaggregates that would be initialized by xᵢ
1035
  [[dcl.init.aggr]] if
1036
 
1037
- - brace elision is not considered for any aggregate element that has a
1038
- dependent non-array type or an array type with a value-dependent
1039
- bound, and
 
 
1040
  - each non-trailing aggregate element that is a pack expansion is
1041
  assumed to correspond to no elements of the initializer list, and
1042
  - a trailing aggregate element that is a pack expansion is assumed to
1043
  correspond to all remaining elements of the initializer list (if any).
1044
 
1045
  If there is no such aggregate element eᵢ for any xᵢ, the aggregate
1046
  deduction candidate is not added to the set. The aggregate deduction
1047
  candidate is derived as above from a hypothetical constructor
1048
  `C`(`T₁`, …, `Tₙ`), where
1049
 
1050
- - if eᵢ is of array type and xᵢ is a *braced-init-list* or
1051
- *string-literal*, `Tᵢ` is an rvalue reference to the declared type of
1052
- eᵢ, and
 
1053
  - otherwise, `Tᵢ` is the declared type of eᵢ,
1054
 
1055
  except that additional parameter packs of the form `Pⱼ` `...` are
1056
  inserted into the parameter list in their original aggregate element
1057
  position corresponding to each non-trailing aggregate element of type
1058
  `Pⱼ` that was skipped because it was a parameter pack, and the trailing
1059
  sequence of parameters corresponding to a trailing aggregate element
1060
  that is a pack expansion (if any) is replaced by a single parameter of
1061
- the form `Tₙ` `...`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1062
 
1063
  When resolving a placeholder for a deduced class type
1064
  [[dcl.type.simple]] where the *template-name* names an alias template
1065
  `A`, the *defining-type-id* of `A` must be of the form
1066
 
@@ -1072,14 +979,16 @@ as specified in [[dcl.type.simple]]. The guides of `A` are the set of
1072
  functions or function templates formed as follows. For each function or
1073
  function template `f` in the guides of the template named by the
1074
  *simple-template-id* of the *defining-type-id*, the template arguments
1075
  of the return type of `f` are deduced from the *defining-type-id* of `A`
1076
  according to the process in [[temp.deduct.type]] with the exception that
1077
- deduction does not fail if not all template arguments are deduced. Let
1078
- `g` denote the result of substituting these deductions into `f`. If
1079
- substitution succeeds, form a function or function template `f'` with
1080
- the following properties and add it to the set of guides of `A`:
 
 
1081
 
1082
  - The function type of `f'` is the function type of `g`.
1083
  - If `f` is a function template, `f'` is a function template whose
1084
  template parameter list consists of all the template parameters of `A`
1085
  (including their default template arguments) that appear in the above
@@ -1089,14 +998,14 @@ the following properties and add it to the set of guides of `A`:
1089
  function template.
1090
  - The associated constraints [[temp.constr.decl]] are the conjunction of
1091
  the associated constraints of `g` and a constraint that is satisfied
1092
  if and only if the arguments of `A` are deducible (see below) from the
1093
  return type.
1094
- - If `f` is a copy deduction candidate [[over.match.class.deduct]], then
1095
- `f'` is considered to be so as well.
1096
- - If `f` was generated from a *deduction-guide*
1097
- [[over.match.class.deduct]], then `f'` is considered to be so as well.
1098
  - The *explicit-specifier* of `f'` is the *explicit-specifier* of `g`
1099
  (if any).
1100
 
1101
  The arguments of a template `A` are said to be deducible from a type `T`
1102
  if, given a class template
@@ -1134,11 +1043,11 @@ If the function or function template was generated from a constructor or
1134
  *deduction-guide* that had an *explicit-specifier*, each such notional
1135
  constructor is considered to have that same *explicit-specifier*. All
1136
  such notional constructors are considered to be public members of the
1137
  hypothetical class type.
1138
 
1139
- [*Example 1*:
1140
 
1141
  ``` cpp
1142
  template <class T> struct A {
1143
  explicit A(const T&, ...) noexcept; // #1
1144
  A(T&&, ...); // #2
@@ -1216,11 +1125,11 @@ F f2 = {Types<X, Y, Z>{}, X{}, Y{}}; // OK, F<X, Y, Z> deduced
1216
  F f3 = {Types<X, Y, Z>{}, X{}, W{}}; // error: conflicting types deduced; operator Y not considered
1217
  ```
1218
 
1219
  — *end example*]
1220
 
1221
- [*Example 2*:
1222
 
1223
  ``` cpp
1224
  template <class T, class U> struct C {
1225
  C(T, U); // #1
1226
  };
@@ -1247,11 +1156,11 @@ Possible exposition-only implementation of the above procedure:
1247
  template <class> class AA;
1248
  template <class V> class AA<A<V>> { };
1249
  template <class T> concept deduces_A = requires { sizeof(AA<T>); };
1250
 
1251
  // f1 is formed from the constructor #1 of C, generating the following function template
1252
- template<T, U>
1253
  auto f1(T, U) -> C<T, U>;
1254
 
1255
  // Deducing arguments for C<T, U> from C<V *, V*> deduces T as V * and U as V *;
1256
  // f1' is obtained by transforming f1 as described by the above procedure.
1257
  template<class V> requires deduces_A<C<V *, V *>>
@@ -1295,64 +1204,60 @@ associated constraints, if any, and relationships between arguments and
1295
  function parameters other than the ranking of conversion sequences.
1296
 
1297
  First, to be a viable function, a candidate function shall have enough
1298
  parameters to agree in number with the arguments in the list.
1299
 
1300
- - If there are *m* arguments in the list, all candidate functions having
1301
- exactly *m* parameters are viable.
1302
- - A candidate function having fewer than *m* parameters is viable only
1303
- if it has an ellipsis in its parameter list [[dcl.fct]]. For the
1304
- purposes of overload resolution, any argument for which there is no
1305
  corresponding parameter is considered to “match the ellipsis”
1306
  [[over.ics.ellipsis]].
1307
- - A candidate function having more than *m* parameters is viable only if
1308
  all parameters following the mᵗʰ have default arguments
1309
  [[dcl.fct.default]]. For the purposes of overload resolution, the
1310
- parameter list is truncated on the right, so that there are exactly
1311
- *m* parameters.
1312
 
1313
  Second, for a function to be viable, if it has associated constraints
1314
  [[temp.constr.decl]], those constraints shall be satisfied
1315
  [[temp.constr.constr]].
1316
 
1317
  Third, for `F` to be a viable function, there shall exist for each
1318
  argument an implicit conversion sequence [[over.best.ics]] that converts
1319
  that argument to the corresponding parameter of `F`. If the parameter
1320
  has reference type, the implicit conversion sequence includes the
1321
  operation of binding the reference, and the fact that an lvalue
1322
- reference to non-`const` cannot be bound to an rvalue and that an rvalue
1323
- reference cannot be bound to an lvalue can affect the viability of the
1324
  function (see  [[over.ics.ref]]).
1325
 
1326
  ### Best viable function <a id="over.match.best">[[over.match.best]]</a>
1327
 
1328
- Define ICS*i*(`F`) as follows:
1329
 
1330
- - If `F` is a static member function, ICS*1*(`F`) is defined such that
1331
- ICS*1*(`F`) is neither better nor worse than ICS*1*(`G`) for any
1332
- function `G`, and, symmetrically, ICS*1*(`G`) is neither better nor
1333
- worse than ICS*1*(`F`);[^8] otherwise,
1334
- - let ICS*i*(`F`) denote the implicit conversion sequence that converts
1335
- the *i*-th argument in the list to the type of the *i*-th parameter of
1336
- viable function `F`. [[over.best.ics]] defines the implicit conversion
1337
  sequences and [[over.ics.rank]] defines what it means for one implicit
1338
  conversion sequence to be a better conversion sequence or worse
1339
  conversion sequence than another.
1340
 
1341
- Given these definitions, a viable function `F1` is defined to be a
1342
- *better* function than another viable function `F2` if for all arguments
1343
- *i*, ICS*i*(`F1`) is not a worse conversion sequence than ICS*i*(`F2`),
1344
- and then
1345
 
1346
- - for some argument *j*, ICS*j*(`F1`) is a better conversion sequence
1347
- than ICS*j*(`F2`), 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 return type of `F1` 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 return type of `F2` to the destination type
1354
  \[*Example 1*:
1355
  ``` cpp
1356
  struct A {
1357
  A();
1358
  operator int();
@@ -1395,11 +1300,11 @@ and then
1395
  parameter-type-lists, and `F1` is more constrained than `F2` according
1396
  to the partial ordering of constraints described in
1397
  [[temp.constr.order]], or if not that,
1398
  - `F1` is a constructor for a class `D`, `F2` is a constructor for a
1399
  base class `B` of `D`, and for all arguments the corresponding
1400
- parameters of `F1` and `F2` have the same type.
1401
  \[*Example 3*:
1402
  ``` cpp
1403
  struct A {
1404
  A(int = 0);
1405
  };
@@ -1439,10 +1344,16 @@ and then
1439
  bool b = 1 < S(); // calls #2
1440
  ```
1441
 
1442
  — *end example*]
1443
  or, if not that
 
 
 
 
 
 
1444
  - `F1` is generated from a *deduction-guide* [[over.match.class.deduct]]
1445
  and `F2` is not, or, if not that,
1446
  - `F1` is the copy deduction candidate [[over.match.class.deduct]] and
1447
  `F2` is not, or, if not that,
1448
  - `F1` is generated from a non-template constructor and `F2` is
@@ -1475,11 +1386,11 @@ and then
1475
 
1476
  — *end example*]
1477
 
1478
  If there is exactly one viable function that is a better function than
1479
  all other viable functions, then it is the one selected by overload
1480
- resolution; otherwise the call is ill-formed.[^9]
1481
 
1482
  [*Example 7*:
1483
 
1484
  ``` cpp
1485
  void Fcn(const int*, short);
@@ -1494,21 +1405,20 @@ void f() {
1494
 
1495
  Fcn(&i, 1L); // calls Fcn(int*, int), because &i → int* is better than &i → const int*
1496
  // and 1L → short and 1L → int are indistinguishable
1497
 
1498
  Fcn(&i, 'c'); // calls Fcn(int*, int), because &i → int* is better than &i → const int*
1499
- // and c → int is better than c → short
1500
  }
1501
  ```
1502
 
1503
  — *end example*]
1504
 
1505
  If the best viable function resolves to a function for which multiple
1506
- declarations were found, and if at least two of these declarations — or
1507
- the declarations they refer to in the case of *using-declaration*s
1508
- specify a default argument that made the function viable, the program is
1509
- ill-formed.
1510
 
1511
  [*Example 8*:
1512
 
1513
  ``` cpp
1514
  namespace A {
@@ -1529,16 +1439,18 @@ void use() {
1529
 
1530
  — *end example*]
1531
 
1532
  #### Implicit conversion sequences <a id="over.best.ics">[[over.best.ics]]</a>
1533
 
 
 
1534
  An *implicit conversion sequence* is a sequence of conversions used to
1535
  convert an argument in a function call to the type of the corresponding
1536
  parameter of the function being called. The sequence of conversions is
1537
  an implicit conversion as defined in [[conv]], which means it is
1538
  governed by the rules for initialization of an object or reference by a
1539
- single expression ([[dcl.init]], [[dcl.init.ref]]).
1540
 
1541
  Implicit conversion sequences are concerned only with the type,
1542
  cv-qualification, and value category of the argument and how these are
1543
  converted to match the corresponding properties of the parameter.
1544
 
@@ -1558,11 +1470,11 @@ forms:
1558
  - an ellipsis conversion sequence [[over.ics.ellipsis]].
1559
 
1560
  However, if the target is
1561
 
1562
  - the first parameter of a constructor or
1563
- - the implicit object parameter of a user-defined conversion function
1564
 
1565
  and the constructor or user-defined conversion function is a candidate
1566
  by
1567
 
1568
  - [[over.match.ctor]], when the argument is the temporary in the second
@@ -1619,22 +1531,29 @@ case is the identity sequence; it contains no “conversion” from
1619
 
1620
  When the parameter has a class type and the argument expression has the
1621
  same type, the implicit conversion sequence is an identity conversion.
1622
  When the parameter has a class type and the argument expression has a
1623
  derived class type, the implicit conversion sequence is a
1624
- derived-to-base conversion from the derived class to the base class.
 
1625
 
1626
  [*Note 4*: There is no such standard conversion; this derived-to-base
1627
  conversion exists only in the description of implicit conversion
1628
  sequences. — *end note*]
1629
 
1630
- A derived-to-base conversion has Conversion rank [[over.ics.scs]].
 
 
 
1631
 
1632
  In all contexts, when converting to the implicit object parameter or
1633
  when converting to the left operand of an assignment operation only
1634
  standard conversion sequences are allowed.
1635
 
 
 
 
1636
  If no conversions are required to match an argument to a parameter type,
1637
  the implicit conversion sequence is the standard conversion sequence
1638
  consisting of the identity conversion [[over.ics.scs]].
1639
 
1640
  If no sequence of conversions can be found to convert an argument to a
@@ -1647,11 +1566,11 @@ conversion sequence designated the *ambiguous conversion sequence*. For
1647
  the purpose of ranking implicit conversion sequences as described in 
1648
  [[over.ics.rank]], the ambiguous conversion sequence is treated as a
1649
  user-defined conversion sequence that is indistinguishable from any
1650
  other user-defined conversion sequence.
1651
 
1652
- [*Note 5*:
1653
 
1654
  This rule prevents a function from becoming non-viable because of an
1655
  ambiguous conversion sequence for one of its parameters.
1656
 
1657
  [*Example 3*:
@@ -1685,19 +1604,19 @@ defined in the following subclauses.
1685
 
1686
  summarizes the conversions defined in [[conv]] and partitions them into
1687
  four disjoint categories: Lvalue Transformation, Qualification
1688
  Adjustment, Promotion, and Conversion.
1689
 
1690
- [*Note 6*: These categories are orthogonal with respect to value
1691
  category, cv-qualification, and data representation: the Lvalue
1692
  Transformations do not change the cv-qualification or data
1693
  representation of the type; the Qualification Adjustments do not change
1694
  the value category or data representation of the type; and the
1695
  Promotions and Conversions do not change the value category or
1696
  cv-qualification of the type. — *end note*]
1697
 
1698
- [*Note 7*: As described in [[conv]], a standard conversion sequence
1699
  either is the Identity conversion by itself (that is, no conversion) or
1700
  consists of one to three conversions from the other four categories. If
1701
  there are two or more conversions in the sequence, the conversions are
1702
  applied in the canonical order: **Lvalue Transformation**, **Promotion**
1703
  or **Conversion**, **Qualification Adjustment**. — *end note*]
@@ -1725,14 +1644,14 @@ Promotion rank; otherwise, the sequence has Exact Match rank.
1725
  A *user-defined conversion sequence* consists of an initial standard
1726
  conversion sequence followed by a user-defined conversion [[class.conv]]
1727
  followed by a second standard conversion sequence. If the user-defined
1728
  conversion is specified by a constructor [[class.conv.ctor]], the
1729
  initial standard conversion sequence converts the source type to the
1730
- type required by the argument of the constructor. If the user-defined
1731
  conversion is specified by a conversion function [[class.conv.fct]], the
1732
  initial standard conversion sequence converts the source type to the
1733
- implicit object parameter of the conversion function.
1734
 
1735
  The second standard conversion sequence converts the result of the
1736
  user-defined conversion to the target type for the sequence; any
1737
  reference binding is included in the second standard conversion
1738
  sequence. Since an implicit conversion sequence is an initialization,
@@ -1760,11 +1679,11 @@ function called (see  [[expr.call]]).
1760
 
1761
  When a parameter of reference type binds directly [[dcl.init.ref]] to an
1762
  argument expression, the implicit conversion sequence is the identity
1763
  conversion, unless the argument expression has a type that is a derived
1764
  class of the parameter type, in which case the implicit conversion
1765
- sequence is a derived-to-base Conversion [[over.best.ics]].
1766
 
1767
  [*Example 4*:
1768
 
1769
  ``` cpp
1770
  struct A {};
@@ -1776,12 +1695,12 @@ int i = f(b); // calls f(B&), an exact match, rather than f(A&), a convers
1776
 
1777
  — *end example*]
1778
 
1779
  If the parameter binds directly to the result of applying a conversion
1780
  function to the argument expression, the implicit conversion sequence is
1781
- a user-defined conversion sequence [[over.ics.user]], with the second
1782
- standard conversion sequence either an identity conversion or, if the
1783
  conversion function returns an entity of a type that is a derived class
1784
  of the parameter type, a derived-to-base conversion.
1785
 
1786
  When a parameter of reference type is not bound directly to an argument
1787
  expression, the conversion sequence is the one required to convert the
@@ -1795,11 +1714,11 @@ Except for an implicit object parameter, for which see 
1795
  [[over.match.funcs]], an implicit conversion sequence cannot be formed
1796
  if it requires binding an lvalue reference other than a reference to a
1797
  non-volatile `const` type to an rvalue or binding an rvalue reference to
1798
  an lvalue other than a function lvalue.
1799
 
1800
- [*Note 8*: This means, for example, that a candidate function cannot be
1801
  a viable function if it has a non-`const` lvalue reference parameter
1802
  (other than the implicit object parameter) and the corresponding
1803
  argument would require a temporary to be created to initialize the
1804
  lvalue reference (see  [[dcl.init.ref]]). — *end note*]
1805
 
@@ -1827,11 +1746,11 @@ is only possible if the parameter has an aggregate type that can be
1827
  initialized from the initializer list according to the rules for
1828
  aggregate initialization [[dcl.init.aggr]], in which case the implicit
1829
  conversion sequence is a user-defined conversion sequence whose second
1830
  standard conversion sequence is an identity conversion.
1831
 
1832
- [*Note 9*:
1833
 
1834
  Aggregate initialization does not require that the members are declared
1835
  in designation order. If, after overload resolution, the order does not
1836
  match for the selected overload, the initialization of the parameter
1837
  will be ill-formed [[dcl.init.list]].
@@ -1860,14 +1779,15 @@ void h() {
1860
  Otherwise, if the parameter type is an aggregate class `X` and the
1861
  initializer list has a single element of type cv `U`, where `U` is `X`
1862
  or a class derived from `X`, the implicit conversion sequence is the one
1863
  required to convert the element to the parameter type.
1864
 
1865
- Otherwise, if the parameter type is a character array [^10] and the
1866
- initializer list has a single element that is an appropriately-typed
1867
- *string-literal* [[dcl.init.string]], the implicit conversion sequence
1868
- is the identity conversion.
 
1869
 
1870
  Otherwise, if the parameter type is `std::initializer_list<X>` and all
1871
  the elements of the initializer list can be implicitly converted to `X`,
1872
  the implicit conversion sequence is the worst conversion necessary to
1873
  convert an element of the list to `X`, or if the initializer list has no
@@ -1877,13 +1797,13 @@ constructor.
1877
 
1878
  [*Example 7*:
1879
 
1880
  ``` cpp
1881
  void f(std::initializer_list<int>);
1882
- f( {} ); // OK: f(initializer_list<int>) identity conversion
1883
- f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
1884
- f( {'a','b'} ); // OK: f(initializer_list<int>) integral promotion
1885
  f( {1.0} ); // error: narrowing
1886
 
1887
  struct A {
1888
  A(std::initializer_list<double>); // #1
1889
  A(std::initializer_list<complex<double>>); // #2
@@ -1894,11 +1814,11 @@ A a{ 1.0,2.0 }; // OK, uses #1
1894
  void g(A);
1895
  g({ "foo", "bar" }); // OK, uses #3
1896
 
1897
  typedef int IA[3];
1898
  void h(const IA&);
1899
- h({ 1, 2, 3 }); // OK: identity conversion
1900
  ```
1901
 
1902
  — *end example*]
1903
 
1904
  Otherwise, if the parameter type is “array of `N` `X`” or “array of
@@ -1916,11 +1836,11 @@ the argument initializer list:
1916
  - If `C` is not an initializer-list constructor and the initializer list
1917
  has a single element of type cv `U`, where `U` is `X` or a class
1918
  derived from `X`, the implicit conversion sequence has Exact Match
1919
  rank if `U` is `X`, or Conversion rank if `U` is derived from `X`.
1920
  - Otherwise, the implicit conversion sequence is a user-defined
1921
- conversion sequence with the second standard conversion sequence an
1922
  identity conversion.
1923
 
1924
  If multiple constructors are viable but none is better than the others,
1925
  the implicit conversion sequence is the ambiguous conversion sequence.
1926
  User-defined conversions are allowed for conversion of the initializer
@@ -1932,61 +1852,61 @@ list elements to the constructor parameter types except as noted in 
1932
  ``` cpp
1933
  struct A {
1934
  A(std::initializer_list<int>);
1935
  };
1936
  void f(A);
1937
- f( {'a', 'b'} ); // OK: f(A(std::initializer_list<int>)) user-defined conversion
1938
 
1939
  struct B {
1940
  B(int, double);
1941
  };
1942
  void g(B);
1943
- g( {'a', 'b'} ); // OK: g(B(int, double)) user-defined conversion
1944
  g( {1.0, 1.0} ); // error: narrowing
1945
 
1946
  void f(B);
1947
  f( {'a', 'b'} ); // error: ambiguous f(A) or f(B)
1948
 
1949
  struct C {
1950
  C(std::string);
1951
  };
1952
  void h(C);
1953
- h({"foo"}); // OK: h(C(std::string("foo")))
1954
 
1955
  struct D {
1956
  D(A, C);
1957
  };
1958
  void i(D);
1959
- i({ {1,2}, {"bar"} }); // OK: i(D(A(std::initializer_list<int>{1,2\), C(std::string("bar"))))}
1960
  ```
1961
 
1962
  — *end example*]
1963
 
1964
  Otherwise, if the parameter has an aggregate type which can be
1965
  initialized from the initializer list according to the rules for
1966
  aggregate initialization [[dcl.init.aggr]], the implicit conversion
1967
- sequence is a user-defined conversion sequence with the second standard
1968
- conversion sequence an identity conversion.
1969
 
1970
  [*Example 9*:
1971
 
1972
  ``` cpp
1973
  struct A {
1974
  int m1;
1975
  double m2;
1976
  };
1977
 
1978
  void f(A);
1979
- f( {'a', 'b'} ); // OK: f(A(int,double)) user-defined conversion
1980
  f( {1.0} ); // error: narrowing
1981
  ```
1982
 
1983
  — *end example*]
1984
 
1985
  Otherwise, if the parameter is a reference, see  [[over.ics.ref]].
1986
 
1987
- [*Note 10*: The rules in this subclause will apply for initializing the
1988
  underlying temporary for the reference. — *end note*]
1989
 
1990
  [*Example 10*:
1991
 
1992
  ``` cpp
@@ -1994,11 +1914,11 @@ struct A {
1994
  int m1;
1995
  double m2;
1996
  };
1997
 
1998
  void f(const A&);
1999
- f( {'a', 'b'} ); // OK: f(A(int,double)) user-defined conversion
2000
  f( {1.0} ); // error: narrowing
2001
 
2002
  void g(const double &);
2003
  g({1}); // same conversion as int to double
2004
  ```
@@ -2011,21 +1931,21 @@ Otherwise, if the parameter type is not a class:
2011
  initializer list, the implicit conversion sequence is the one required
2012
  to convert the element to the parameter type;
2013
  \[*Example 11*:
2014
  ``` cpp
2015
  void f(int);
2016
- f( {'a'} ); // OK: same conversion as char to int
2017
  f( {1.0} ); // error: narrowing
2018
  ```
2019
 
2020
  — *end example*]
2021
  - if the initializer list has no elements, the implicit conversion
2022
  sequence is the identity conversion.
2023
  \[*Example 12*:
2024
  ``` cpp
2025
  void f(int);
2026
- f( { } ); // OK: identity conversion
2027
  ```
2028
 
2029
  — *end example*]
2030
 
2031
  In all cases other than those enumerated above, no conversion is
@@ -2214,19 +2134,41 @@ indistinguishable unless one of the following rules applies:
2214
  - A conversion that does not convert a pointer or a pointer to member to
2215
  `bool` is better than one that does.
2216
  - A conversion that promotes an enumeration whose underlying type is
2217
  fixed to its underlying type is better than one that promotes to the
2218
  promoted underlying type, if the two are different.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2219
  - If class `B` is derived directly or indirectly from class `A`,
2220
  conversion of `B*` to `A*` is better than conversion of `B*` to
2221
  `void*`, and conversion of `A*` to `void*` is better than conversion
2222
  of `B*` to `void*`.
2223
  - If class `B` is derived directly or indirectly from class `A` and
2224
  class `C` is derived directly or indirectly from `B`,
2225
  - conversion of `C*` to `B*` is better than conversion of `C*` to
2226
  `A*`,
2227
- \[*Example 8*:
2228
  ``` cpp
2229
  struct A {};
2230
  struct B : public A {};
2231
  struct C : public B {};
2232
  C* pc;
@@ -2255,30 +2197,31 @@ indistinguishable unless one of the following rules applies:
2255
  types only in the context of comparing the second standard conversion
2256
  sequence of an initialization by user-defined conversion (see 
2257
  [[over.match.best]]); in all other contexts, the source types will be
2258
  the same and the target types will be different. — *end note*]
2259
 
2260
- ## Address of overloaded function <a id="over.over">[[over.over]]</a>
2261
 
2262
- A use of a function name without arguments is resolved to a function, a
2263
- pointer to function, or a pointer to member function for a specific
2264
- function that is chosen from a set of selected functions determined
2265
- based on the target type required in the context (if any), as described
2266
- below. The target can be
 
2267
 
2268
- - an object or reference being initialized ([[dcl.init]],
2269
- [[dcl.init.ref]], [[dcl.init.list]]),
2270
  - the left side of an assignment [[expr.ass]],
2271
  - a parameter of a function [[expr.call]],
2272
  - a parameter of a user-defined operator [[over.oper]],
2273
  - the return value of a function, operator function, or conversion
2274
  [[stmt.return]],
2275
- - an explicit type conversion ([[expr.type.conv]],
2276
- [[expr.static.cast]], [[expr.cast]]), or
2277
  - a non-type *template-parameter* [[temp.arg.nontype]].
2278
 
2279
- The function name can be preceded by the `&` operator.
2280
 
2281
  [*Note 1*: Any redundant set of parentheses surrounding the function
2282
  name is ignored [[expr.prim.paren]]. — *end note*]
2283
 
2284
  If there is no target, all non-template functions named are selected.
@@ -2287,30 +2230,23 @@ function type `FT` of the target type if `F` (after possibly applying
2287
  the function pointer conversion [[conv.fctptr]]) is identical to `FT`.
2288
 
2289
  [*Note 2*: That is, the class of which the function is a member is
2290
  ignored when matching a pointer-to-member-function type. — *end note*]
2291
 
2292
- For each function template designated by the name, template argument
2293
- deduction is done [[temp.deduct.funcaddr]], and if the argument
2294
- deduction succeeds, the resulting template argument list is used to
2295
- generate a single function template specialization, which is added to
2296
- the set of selected functions considered.
2297
 
2298
- [*Note 3*: As described in  [[temp.arg.explicit]], if deduction fails
2299
- and the function template name is followed by an explicit template
2300
- argument list, the *template-id* is then examined to see whether it
2301
- identifies a single function template specialization. If it does, the
2302
- *template-id* is considered to be an lvalue for that function template
2303
- specialization. The target type is not used in that
2304
- determination. — *end note*]
2305
 
2306
- Non-member functions and static member functions match targets of
2307
- function pointer type or reference to function type. Non-static member
2308
- functions match targets of pointer-to-member-function type. If a
2309
- non-static member function is selected, the reference to the overloaded
2310
- function name is required to have the form of a pointer to member as
2311
- described in  [[expr.unary.op]].
2312
 
2313
  All functions with associated constraints that are not satisfied
2314
  [[temp.constr.decl]] are eliminated from the set of selected functions.
2315
  If more than one function in the set remains, all function template
2316
  specializations in the set are eliminated if the set also contains a
@@ -2358,13 +2294,13 @@ int (X::*p5)(int) = &(X::f); // error: wrong syntax for
2358
  int (*p6)(long) = &(X::f); // OK
2359
  ```
2360
 
2361
  — *end example*]
2362
 
2363
- [*Note 4*: If `f()` and `g()` are both overloaded functions, the cross
2364
- product of possibilities must be considered to resolve `f(&g)`, or the
2365
- equivalent expression `f(g)`. — *end note*]
2366
 
2367
  [*Note 5*:
2368
 
2369
  Even if `B` is a public base of `D`, we have
2370
 
@@ -2378,17 +2314,19 @@ void (*p2)(B*) = &g; // error
2378
 
2379
  — *end note*]
2380
 
2381
  ## Overloaded operators <a id="over.oper">[[over.oper]]</a>
2382
 
2383
- A function declaration having one of the following
2384
- *operator-function-id*s as its name declares an *operator function*. A
2385
- function template declaration having one of the following
2386
- *operator-function-id*s as its name declares an *operator function
2387
- template*. A specialization of an operator function template is also an
2388
- operator function. An operator function is said to *implement* the
2389
- operator named in its *operator-function-id*.
 
 
2390
 
2391
  ``` bnf
2392
  operator-function-id:
2393
  operator operator
2394
  ```
@@ -2444,26 +2382,30 @@ void* p = operator new(sizeof(int)*n);
2444
  — *end example*]
2445
 
2446
  The allocation and deallocation functions, `operator` `new`, `operator`
2447
  `new[]`, `operator` `delete`, and `operator` `delete[]`, are described
2448
  completely in  [[basic.stc.dynamic]]. The attributes and restrictions
2449
- found in the rest of this subclause do not apply to them unless
2450
  explicitly stated in  [[basic.stc.dynamic]].
2451
 
2452
  The `co_await` operator is described completely in  [[expr.await]]. The
2453
- attributes and restrictions found in the rest of this subclause do not
2454
  apply to it unless explicitly stated in  [[expr.await]].
2455
 
2456
- An operator function shall either be a non-static member function or be
2457
- a non-member function that has at least one parameter whose type is a
2458
- class, a reference to a class, an enumeration, or a reference to an
2459
- enumeration. It is not possible to change the precedence, grouping, or
2460
- number of operands of operators. The meaning of the operators `=`,
2461
- (unary) `&`, and `,` (comma), predefined for each type, can be changed
2462
- for specific class types by defining operator functions that implement
2463
- these operators. Likewise, the meaning of the operators (unary) `&` and
2464
- `,` (comma) can be changed for specific enumeration types. Operator
 
 
 
 
2465
  functions are inherited in the same manner as other base class
2466
  functions.
2467
 
2468
  An operator function shall be a prefix unary, binary, function call,
2469
  subscripting, class member access, increment, or decrement operator
@@ -2476,25 +2418,25 @@ to be an lvalue when applied to basic types; this is not required by
2476
  operator functions. — *end note*]
2477
 
2478
  An operator function cannot have default arguments [[dcl.fct.default]],
2479
  except where explicitly stated below. Operator functions cannot have
2480
  more or fewer parameters than the number required for the corresponding
2481
- operator, as described in the rest of this subclause.
2482
 
2483
  Operators not mentioned explicitly in subclauses  [[over.ass]] through 
2484
  [[over.inc]] act as ordinary unary and binary operators obeying the
2485
  rules of  [[over.unary]] or  [[over.binary]].
2486
 
2487
  ### Unary operators <a id="over.unary">[[over.unary]]</a>
2488
 
2489
  A *prefix unary operator function* is a function named `operator@` for a
2490
  prefix *unary-operator* `@` [[expr.unary.op]] that is either a
2491
- non-static member function [[class.mfct]] with no parameters or a
2492
- non-member function with one parameter. For a *unary-expression* of the
2493
- form `@ cast-expression`, the operator function is selected by overload
2494
- resolution [[over.match.oper]]. If a member function is selected, the
2495
- expression is interpreted as
2496
 
2497
  ``` bnf
2498
  cast-expression '.' operator '@' '('')'
2499
  ```
2500
 
@@ -2503,26 +2445,26 @@ interpreted as
2503
 
2504
  ``` bnf
2505
  operator '@' '(' cast-expression ')'
2506
  ```
2507
 
2508
- [*Note 1*: The operators `++` and `\dcr` [[expr.pre.incr]] are
2509
- described in  [[over.inc]]. — *end note*]
2510
 
2511
- The unary and binary forms of the same operator are considered to have
2512
- the same name.
2513
-
2514
- [*Note 2*: Consequently, a unary operator can hide a binary operator
2515
  from an enclosing scope, and vice versa. — *end note*]
2516
 
2517
  ### Binary operators <a id="over.binary">[[over.binary]]</a>
2518
 
 
 
2519
  A *binary operator function* is a function named `operator@` for a
2520
  binary operator `@` that is either a non-static member function
2521
- [[class.mfct]] with one parameter or a non-member function with two
2522
- parameters. For an expression `x @ y` with subexpressions x and y, the
2523
- operator function is selected by overload resolution
2524
  [[over.match.oper]]. If a member function is selected, the expression is
2525
  interpreted as
2526
 
2527
  ``` bnf
2528
  x '.' operator '@' '(' y ')'
@@ -2597,69 +2539,74 @@ void f() {
2597
  — *end note*]
2598
 
2599
  ### Function call <a id="over.call">[[over.call]]</a>
2600
 
2601
  A *function call operator function* is a function named `operator()`
2602
- that is a non-static member function with an arbitrary number of
2603
- parameters. It may have default arguments. For an expression of the form
2604
 
2605
  ``` bnf
2606
  postfix-expression '(' expression-listₒₚₜ ')'
2607
  ```
2608
 
2609
  where the *postfix-expression* is of class type, the operator function
2610
  is selected by overload resolution [[over.call.object]]. If a surrogate
2611
- call function for a conversion function named `operator`
2612
- *conversion-type-id* is selected, the expression is interpreted as
 
 
2613
 
2614
  ``` bnf
2615
- postfix-expression '.' operator conversion-type-id '('')' '(' expression-listₒₚₜ ')'
2616
  ```
2617
 
2618
  Otherwise, the expression is interpreted as
2619
 
2620
  ``` bnf
2621
  postfix-expression '.' operator '('')' '(' expression-listₒₚₜ ')'
2622
  ```
2623
 
2624
  ### Subscripting <a id="over.sub">[[over.sub]]</a>
2625
 
2626
- A *subscripting operator function* is a function named `operator[]` that
2627
- is a non-static member function with exactly one parameter. For an
2628
- expression of the form
2629
 
2630
  ``` bnf
2631
- postfix-expression '[' expr-or-braced-init-list ']'
2632
  ```
2633
 
2634
  the operator function is selected by overload resolution
2635
  [[over.match.oper]]. If a member function is selected, the expression is
2636
  interpreted as
2637
 
2638
  ``` bnf
2639
- postfix-expression . operator '['']' '(' expr-or-braced-init-list ')'
2640
  ```
2641
 
2642
  [*Example 1*:
2643
 
2644
  ``` cpp
2645
  struct X {
2646
  Z operator[](std::initializer_list<int>);
 
2647
  };
2648
  X x;
2649
- x[{1,2,3}] = 7; // OK: meaning x.operator[]({1,2,3\)}
 
2650
  int a[10];
2651
  a[{1,2,3}] = 7; // error: built-in subscript operator
 
2652
  ```
2653
 
2654
  — *end example*]
2655
 
2656
  ### Class member access <a id="over.ref">[[over.ref]]</a>
2657
 
2658
  A *class member access operator function* is a function named
2659
- `operator->` that is a non-static member function taking no parameters.
2660
- For an expression of the form
2661
 
2662
  ``` bnf
2663
  postfix-expression '->' templateₒₚₜ id-expression
2664
  ```
2665
 
@@ -2671,18 +2618,19 @@ the operator function is selected by overload resolution
2671
  ```
2672
 
2673
  ### Increment and decrement <a id="over.inc">[[over.inc]]</a>
2674
 
2675
  An *increment operator function* is a function named `operator++`. If
2676
- this function is a non-static member function with no parameters, or a
2677
- non-member function with one parameter, it defines the prefix increment
2678
- operator `++` for objects of that type. If the function is a non-static
2679
- member function with one parameter (which shall be of type `int`) or a
2680
- non-member function with two parameters (the second of which shall be of
2681
- type `int`), it defines the postfix increment operator `++` for objects
2682
- of that type. When the postfix increment is called as a result of using
2683
- the `++` operator, the `int` argument will have value zero.[^11]
 
2684
 
2685
  [*Example 1*:
2686
 
2687
  ``` cpp
2688
  struct X {
@@ -2707,12 +2655,12 @@ void f(X a, Y b) {
2707
  }
2708
  ```
2709
 
2710
  — *end example*]
2711
 
2712
- A *decrement operator function* is a function named `operator\dcr` and
2713
- is handled analogously to an increment operator function.
2714
 
2715
  ## Built-in operators <a id="over.built">[[over.built]]</a>
2716
 
2717
  The candidate operator functions that represent the built-in operators
2718
  defined in [[expr.compound]] are specified in this subclause. These
@@ -2730,63 +2678,42 @@ that can be converted to a type appropriate for the operator. Also note
2730
  that some of the candidate operator functions given in this subclause
2731
  are more permissive than the built-in operators themselves. As described
2732
  in  [[over.match.oper]], after a built-in operator is selected by
2733
  overload resolution the expression is subject to the requirements for
2734
  the built-in operator given in [[expr.compound]], and therefore to any
2735
- additional semantic constraints given there. If there is a user-written
2736
- candidate with the same name and parameter types as a built-in candidate
2737
- operator function, the built-in operator function is hidden and is not
2738
- included in the set of candidate functions. — *end note*]
2739
 
2740
  In this subclause, the term *promoted integral type* is used to refer to
2741
- those integral types which are preserved by integral promotion
2742
- [[conv.prom]] (including e.g. `int` and `long` but excluding e.g.
2743
- `char`).
2744
 
2745
  [*Note 2*: In all cases where a promoted integral type is required, an
2746
  operand of unscoped enumeration type will be acceptable by way of the
2747
  integral promotions. — *end note*]
2748
 
2749
  In the remainder of this subclause, *vq* represents either `volatile` or
2750
  no cv-qualifier.
2751
 
2752
- For every pair (`T`, *vq*), where `T` is an arithmetic type other than
2753
- `bool`, there exist candidate operator functions of the form
 
 
2754
 
2755
  ``` cpp
2756
  vq T& operator++(vq T&);
2757
  T operator++(vq T&, int);
2758
- ```
2759
-
2760
- For every pair (`T`, *vq*), where `T` is an arithmetic type other than
2761
- `bool`, there exist candidate operator functions of the form
2762
-
2763
- ``` cpp
2764
  vq T& operator--(vq T&);
2765
  T operator--(vq T&, int);
2766
  ```
2767
 
2768
- For every pair (`T`, *vq*), where `T` is a cv-qualified or
2769
- cv-unqualified object type, there exist candidate operator functions of
2770
- the form
2771
-
2772
- ``` cpp
2773
- T*vq& operator++(T*vq&);
2774
- T*vq& operator--(T*vq&);
2775
- T* operator++(T*vq&, int);
2776
- T* operator--(T*vq&, int);
2777
- ```
2778
-
2779
- For every cv-qualified or cv-unqualified object type `T`, there exist
2780
- candidate operator functions of the form
2781
-
2782
- ``` cpp
2783
- T& operator*(T*);
2784
- ```
2785
-
2786
- For every function type `T` that does not have cv-qualifiers or a
2787
- *ref-qualifier*, there exist candidate operator functions of the form
2788
 
2789
  ``` cpp
2790
  T& operator*(T*);
2791
  ```
2792
 
@@ -2794,12 +2721,12 @@ For every type `T` there exist candidate operator functions of the form
2794
 
2795
  ``` cpp
2796
  T* operator+(T*);
2797
  ```
2798
 
2799
- For every floating-point or promoted integral type `T`, there exist
2800
- candidate operator functions of the form
2801
 
2802
  ``` cpp
2803
  T operator+(T);
2804
  T operator-(T);
2805
  ```
@@ -3004,22 +2931,23 @@ literal-operator-id:
3004
 
3005
  The *string-literal* or *user-defined-string-literal* in a
3006
  *literal-operator-id* shall have no *encoding-prefix* and shall contain
3007
  no characters other than the implicit terminating `'\0'`. The
3008
  *ud-suffix* of the *user-defined-string-literal* or the *identifier* in
3009
- a *literal-operator-id* is called a *literal suffix identifier*. Some
 
3010
  literal suffix identifiers are reserved for future standardization; see 
3011
  [[usrlit.suffix]]. A declaration whose *literal-operator-id* uses such a
3012
  literal suffix identifier is ill-formed, no diagnostic required.
3013
 
3014
- A declaration whose *declarator-id* is a *literal-operator-id* shall be
3015
- a declaration of a namespace-scope function or function template (it
3016
- could be a friend function [[class.friend]]), an explicit instantiation
3017
- or specialization of a function template, or a *using-declaration*
3018
- [[namespace.udecl]]. A function declared with a *literal-operator-id* is
3019
- a *literal operator*. A function template declared with a
3020
- *literal-operator-id* is a *literal operator template*.
3021
 
3022
  The declaration of a literal operator shall have a
3023
  *parameter-declaration-clause* equivalent to one of the following:
3024
 
3025
  ``` cpp
@@ -3061,24 +2989,26 @@ language linkage.
3061
  invoked implicitly through user-defined literals [[lex.ext]]. However,
3062
  except for the constraints described above, they are ordinary
3063
  namespace-scope functions and function templates. In particular, they
3064
  are looked up like ordinary functions and function templates and they
3065
  follow the same overload resolution rules. Also, they can be declared
3066
- `inline` or `constexpr`, they may have internal, module, or external
3067
  linkage, they can be called explicitly, their addresses can be taken,
3068
  etc. — *end note*]
3069
 
3070
  [*Example 1*:
3071
 
3072
  ``` cpp
3073
  void operator ""_km(long double); // OK
3074
- string operator "" _i18n(const char*, std::size_t); // OK
3075
- template <char...> double operator "" _\u03C0(); // OK: UCN for lowercase pi
3076
  float operator ""_e(const char*); // OK
3077
- float operator ""E(const char*); // error: reserved literal suffix~([usrlit.suffix], [lex.ext])
3078
- double operator""_Bq(long double); // OK: does not use the reserved identifier _Bq[lex.name]
3079
- double operator"" _Bq(long double); // uses the reserved identifier _Bq[lex.name]
 
 
3080
  float operator " "B(const char*); // error: non-empty string-literal
3081
  string operator ""5X(const char*, std::size_t); // error: invalid literal suffix identifier
3082
  double operator ""_miles(double); // error: invalid parameter-declaration-clause
3083
  template <char...> int operator ""_j(const char*); // error: invalid parameter-declaration-clause
3084
  extern "C" void operator ""_m(long double); // error: C language linkage
@@ -3087,24 +3017,24 @@ extern "C" void operator "" _m(long double); // error: C language linkage
3087
  — *end example*]
3088
 
3089
  <!-- Link reference definitions -->
3090
  [basic.lookup]: basic.md#basic.lookup
3091
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
 
 
3092
  [basic.stc.dynamic]: basic.md#basic.stc.dynamic
3093
  [class.access]: class.md#class.access
3094
  [class.conv]: class.md#class.conv
3095
  [class.conv.ctor]: class.md#class.conv.ctor
3096
  [class.conv.fct]: class.md#class.conv.fct
3097
  [class.copy.assign]: class.md#class.copy.assign
3098
  [class.copy.ctor]: class.md#class.copy.ctor
3099
  [class.friend]: class.md#class.friend
3100
  [class.inhctor.init]: class.md#class.inhctor.init
3101
  [class.mem]: class.md#class.mem
3102
- [class.member.lookup]: class.md#class.member.lookup
3103
  [class.mfct]: class.md#class.mfct
3104
- [class.static]: class.md#class.static
3105
- [class.this]: class.md#class.this
3106
  [conv]: expr.md#conv
3107
  [conv.array]: expr.md#conv.array
3108
  [conv.bool]: expr.md#conv.bool
3109
  [conv.double]: expr.md#conv.double
3110
  [conv.fctptr]: expr.md#conv.fctptr
@@ -3115,14 +3045,13 @@ extern "C" void operator "" _m(long double); // error: C language linkage
3115
  [conv.lval]: expr.md#conv.lval
3116
  [conv.mem]: expr.md#conv.mem
3117
  [conv.prom]: expr.md#conv.prom
3118
  [conv.ptr]: expr.md#conv.ptr
3119
  [conv.qual]: expr.md#conv.qual
 
3120
  [cpp.concat]: cpp.md#cpp.concat
3121
  [cpp.stringize]: cpp.md#cpp.stringize
3122
- [dcl.array]: dcl.md#dcl.array
3123
- [dcl.decl]: dcl.md#dcl.decl
3124
  [dcl.fct]: dcl.md#dcl.fct
3125
  [dcl.fct.def.delete]: dcl.md#dcl.fct.def.delete
3126
  [dcl.fct.default]: dcl.md#dcl.fct.default
3127
  [dcl.fct.spec]: dcl.md#dcl.fct.spec
3128
  [dcl.init]: dcl.md#dcl.init
@@ -3130,12 +3059,11 @@ extern "C" void operator "" _m(long double); // error: C language linkage
3130
  [dcl.init.list]: dcl.md#dcl.init.list
3131
  [dcl.init.ref]: dcl.md#dcl.init.ref
3132
  [dcl.init.string]: dcl.md#dcl.init.string
3133
  [dcl.type.class.deduct]: dcl.md#dcl.type.class.deduct
3134
  [dcl.type.simple]: dcl.md#dcl.type.simple
3135
- [dcl.typedef]: dcl.md#dcl.typedef
3136
- [except.spec]: except.md#except.spec
3137
  [expr.arith.conv]: expr.md#expr.arith.conv
3138
  [expr.ass]: expr.md#expr.ass
3139
  [expr.await]: expr.md#expr.await
3140
  [expr.call]: expr.md#expr.call
3141
  [expr.cast]: expr.md#expr.cast
@@ -3143,10 +3071,11 @@ extern "C" void operator "" _m(long double); // error: C language linkage
3143
  [expr.cond]: expr.md#expr.cond
3144
  [expr.eq]: expr.md#expr.eq
3145
  [expr.mptr.oper]: expr.md#expr.mptr.oper
3146
  [expr.pre.incr]: expr.md#expr.pre.incr
3147
  [expr.prim.paren]: expr.md#expr.prim.paren
 
3148
  [expr.rel]: expr.md#expr.rel
3149
  [expr.spaceship]: expr.md#expr.spaceship
3150
  [expr.static.cast]: expr.md#expr.static.cast
3151
  [expr.sub]: expr.md#expr.sub
3152
  [expr.type.conv]: expr.md#expr.type.conv
@@ -3154,38 +3083,43 @@ extern "C" void operator "" _m(long double); // error: C language linkage
3154
  [lex.ext]: lex.md#lex.ext
3155
  [namespace.udecl]: dcl.md#namespace.udecl
3156
  [over]: #over
3157
  [over.ass]: #over.ass
3158
  [over.best.ics]: #over.best.ics
 
3159
  [over.binary]: #over.binary
 
3160
  [over.built]: #over.built
3161
  [over.call]: #over.call
3162
  [over.call.func]: #over.call.func
3163
  [over.call.object]: #over.call.object
3164
- [over.dcl]: #over.dcl
3165
  [over.ics.ellipsis]: #over.ics.ellipsis
3166
  [over.ics.list]: #over.ics.list
3167
  [over.ics.rank]: #over.ics.rank
3168
  [over.ics.ref]: #over.ics.ref
3169
  [over.ics.scs]: #over.ics.scs
3170
  [over.ics.user]: #over.ics.user
3171
  [over.inc]: #over.inc
3172
  [over.literal]: #over.literal
3173
- [over.load]: #over.load
3174
  [over.match]: #over.match
3175
  [over.match.best]: #over.match.best
 
3176
  [over.match.call]: #over.match.call
 
3177
  [over.match.class.deduct]: #over.match.class.deduct
3178
  [over.match.conv]: #over.match.conv
3179
  [over.match.copy]: #over.match.copy
3180
  [over.match.ctor]: #over.match.ctor
3181
  [over.match.funcs]: #over.match.funcs
 
 
3182
  [over.match.list]: #over.match.list
3183
  [over.match.oper]: #over.match.oper
3184
  [over.match.ref]: #over.match.ref
3185
  [over.match.viable]: #over.match.viable
3186
  [over.oper]: #over.oper
 
3187
  [over.over]: #over.over
3188
  [over.pre]: #over.pre
3189
  [over.ref]: #over.ref
3190
  [over.sub]: #over.sub
3191
  [over.unary]: #over.unary
@@ -3195,73 +3129,63 @@ extern "C" void operator "" _m(long double); // error: C language linkage
3195
  [temp.constr.constr]: temp.md#temp.constr.constr
3196
  [temp.constr.decl]: temp.md#temp.constr.decl
3197
  [temp.constr.order]: temp.md#temp.constr.order
3198
  [temp.deduct]: temp.md#temp.deduct
3199
  [temp.deduct.funcaddr]: temp.md#temp.deduct.funcaddr
 
3200
  [temp.deduct.type]: temp.md#temp.deduct.type
3201
  [temp.dep]: temp.md#temp.dep
3202
  [temp.dep.type]: temp.md#temp.dep.type
3203
  [temp.func.order]: temp.md#temp.func.order
3204
  [temp.over]: temp.md#temp.over
3205
- [temp.over.link]: temp.md#temp.over.link
3206
  [temp.variadic]: temp.md#temp.variadic
3207
  [usrlit.suffix]: library.md#usrlit.suffix
3208
 
3209
- [^1]: When a parameter type includes a function type, such as in the
3210
- case of a parameter type that is a pointer to function, the `const`
3211
- and `volatile` type-specifiers at the outermost level of the
3212
- parameter type specifications for the inner function type are also
3213
- ignored.
3214
-
3215
- [^2]: The process of argument deduction fully determines the parameter
3216
  types of the function template specializations, i.e., the parameters
3217
  of function template specializations contain no template parameter
3218
  types. Therefore, except where specified otherwise, function
3219
  template specializations and non-template functions [[dcl.fct]] are
3220
  treated equivalently for the remainder of overload resolution.
3221
 
3222
- [^3]: Note that cv-qualifiers on the type of objects are significant in
3223
  overload resolution for both glvalue and class prvalue objects.
3224
 
3225
- [^4]: An implied object argument must be contrived to correspond to the
3226
  implicit object parameter attributed to member functions during
3227
  overload resolution. It is not used in the call to the selected
3228
  function. Since the member functions all have the same implicit
3229
  object parameter, the contrived object will not be the cause to
3230
  select or reject a function.
3231
 
3232
- [^5]: Note that this construction can yield candidate call functions
3233
  that cannot be differentiated one from the other by overload
3234
  resolution because they have identical declarations or differ only
3235
  in their return type. The call will be ambiguous if overload
3236
  resolution cannot select a match to the call that is uniquely better
3237
  than such undifferentiable functions.
3238
 
3239
- [^6]: If the set of candidate functions is empty, overload resolution is
3240
  unsuccessful.
3241
 
3242
- [^7]: If the value returned by the `operator->` function has class type,
3243
- this may result in selecting and calling another `operator->`
3244
  function. The process repeats until an `operator->` function returns
3245
  a value of non-class type.
3246
 
3247
- [^8]: If a function is a static member function, this definition means
3248
- that the first argument, the implied object argument, has no effect
3249
- in the determination of whether the function is better or worse than
3250
- any other function.
3251
-
3252
- [^9]: The algorithm for selecting the best viable function is linear in
3253
  the number of viable functions. Run a simple tournament to find a
3254
  function `W` that is not worse than any opponent it faced. Although
3255
- another function `F` that `W` did not face might be at least as good
3256
- as `W`, `F` cannot be the best function because at some point in the
3257
- tournament `F` encountered another function `G` such that `F` was
3258
- not better than `G`. Hence, either `W` is the best function or there
3259
- is no best function. So, make a second pass over the viable
3260
- functions to verify that `W` is better than all other functions.
 
3261
 
3262
- [^10]: Since there are no parameters of array type, this will only occur
3263
  as the referenced type of a reference parameter.
3264
 
3265
- [^11]: Calling `operator++` explicitly, as in expressions like
3266
  `a.operator++(2)`, has no special properties: The argument to
3267
  `operator++` is `2`.
 
1
  # Overloading <a id="over">[[over]]</a>
2
 
3
  ## Preamble <a id="over.pre">[[over.pre]]</a>
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 named in a call, which function declaration is being
10
+ referenced and the validity of the call are determined by comparing the
11
+ types of the arguments at the point of use with the types of the
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);
 
23
  abs(1.0); // calls abs(double);
24
  ```
25
 
26
  — *end example*]
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  ## Overload resolution <a id="over.match">[[over.match]]</a>
29
 
30
+ ### General <a id="over.match.general">[[over.match.general]]</a>
31
+
32
  Overload resolution is a mechanism for selecting the best function to
33
  call given a list of expressions that are to be the arguments of the
34
  call and a set of *candidate functions* that can be called based on the
35
  context of the call. The selection criteria for the best function are
36
  the number of arguments, how well the arguments match the
37
  parameter-type-list of the candidate function, how well (for non-static
38
+ member functions) the object matches the object parameter, and certain
39
+ other properties of the candidate function.
40
 
41
  [*Note 1*: The function selected by overload resolution is not
42
  guaranteed to be appropriate for the context. Other restrictions, such
43
  as the accessibility of the function, can make its use in the calling
44
  context ill-formed. — *end note*]
 
88
  [[over.built]], or is a function that is not deleted and is accessible
89
  from the context in which overload resolution was performed.
90
 
91
  ### Candidate functions and argument lists <a id="over.match.funcs">[[over.match.funcs]]</a>
92
 
93
+ #### General <a id="over.match.funcs.general">[[over.match.funcs.general]]</a>
94
+
95
  The subclauses of  [[over.match.funcs]] describe the set of candidate
96
  functions and the argument list submitted to overload resolution in each
97
  context in which overload resolution is used. The source transformations
98
  and constructions defined in these subclauses are only for the purpose
99
  of describing the overload resolution process. An implementation is not
100
  required to use such transformations and constructions.
101
 
102
  The set of candidate functions can contain both member and non-member
103
+ functions to be resolved against the same argument list. If a member
104
+ function is
105
+
106
+ - an implicit object member function that is not a constructor, or
107
+ - a static member function and the argument list includes an implied
108
+ object argument,
109
+
110
+ it is considered to have an extra first parameter, called the
111
+ *implicit object parameter*, which represents the object for which the
112
+ member function has been called.
113
 
114
  Similarly, when appropriate, the context can construct an argument list
115
  that contains an *implied object argument* as the first argument in the
116
  list to denote the object to be operated on.
117
 
118
+ For implicit object member functions, the type of the implicit object
119
  parameter is
120
 
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 `&&`
 
125
 
126
  where `X` is the class of which the function is a member and cv is the
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
 
133
+ For conversion functions that are implicit object member functions, the
134
+ function is considered to be a member of the class of the implied object
135
+ argument for the purpose of defining the type of the implicit object
136
+ parameter. For non-conversion functions that are implicit object member
137
+ functions nominated by a *using-declaration* in a derived class, the
138
+ function is considered to be a member of the derived class for the
139
+ purpose of defining the type of the implicit object parameter. For
140
+ static member functions, the implicit object parameter is considered to
141
+ match any object (since if the function is selected, the object is
142
+ discarded).
143
 
144
  [*Note 1*: No actual type is established for the implicit object
145
  parameter of a static member function, and no attempt will be made to
146
  determine a conversion sequence for that parameter
147
  [[over.match.best]]. — *end note*]
148
 
149
  During overload resolution, the implied object argument is
150
  indistinguishable from other arguments. The implicit object parameter,
151
  however, retains its identity since no user-defined conversions can be
152
+ applied to achieve a type match with it. For implicit object member
153
+ functions declared without a *ref-qualifier*, even if the implicit
154
+ object parameter is not const-qualified, an rvalue can be bound to the
155
  parameter as long as in all other respects the argument can be converted
156
  to the type of the implicit object parameter.
157
 
158
  [*Note 2*: The fact that such an argument is an rvalue does not affect
159
  the ranking of implicit conversion sequences
160
  [[over.ics.rank]]. — *end note*]
161
 
162
  Because other than in list-initialization only one user-defined
163
  conversion is allowed in an implicit conversion sequence, special rules
164
+ apply when selecting the best user-defined conversion
165
+ [[over.match.best]], [[over.best.ics]].
166
 
167
  [*Example 2*:
168
 
169
  ``` cpp
170
  class T {
 
179
  T a = 1; // error: no viable conversion (T(C(1)) not considered)
180
  ```
181
 
182
  — *end example*]
183
 
184
+ In each case where conversion functions of a class `S` are considered
185
+ for initializing an object or reference of type `T`, the candidate
186
+ functions include the result of a search for the
187
+ *conversion-function-id* `operator T` in `S`.
188
+
189
+ [*Note 3*: This search can find a specialization of a conversion
190
+ function template [[basic.lookup]]. — *end note*]
191
+
192
+ Each such case also defines sets of *permissible types* for explicit and
193
+ non-explicit conversion functions; each (non-template) conversion
194
+ function that
195
+
196
+ - is a non-hidden member of `S`,
197
+ - yields a permissible type, and,
198
+ - for the former set, is non-explicit
199
+
200
+ is also a candidate function. If initializing an object, for any
201
+ permissible type cv `U`, any *cv2* `U`, *cv2* `U&`, or *cv2* `U&&` is
202
+ also a permissible type. If the set of permissible types for explicit
203
+ conversion functions is empty, any candidates that are explicit are
204
+ discarded.
205
+
206
  In each case where a candidate is a function template, candidate
207
  function template specializations are generated using template argument
208
+ deduction [[temp.over]], [[temp.deduct]]. If a constructor template or
209
+ conversion function template has an *explicit-specifier* whose
210
  *constant-expression* is value-dependent [[temp.dep]], template argument
211
+ deduction is performed first and then, if the context admits only
212
+ candidates that are not explicit and the generated specialization is
213
  explicit [[dcl.fct.spec]], it will be removed from the candidate set.
214
  Those candidates are then handled as candidate functions in the usual
215
+ way.[^1]
 
 
 
216
 
217
+ A given name can refer to, or a conversion can consider, one or more
218
+ function templates as well as a set of non-template functions. In such a
219
+ case, the candidate functions generated from each function template are
220
+ combined with the set of non-template candidate functions.
221
+
222
+ A defaulted move special member function
223
+ [[class.copy.ctor]], [[class.copy.assign]] that is defined as deleted is
224
+ excluded from the set of candidate functions in all contexts. A
225
+ constructor inherited from class type `C` [[class.inhctor.init]] that
226
+ has a first parameter of type “reference to *cv1* `P`” (including such a
227
+ constructor instantiated from a template) is excluded from the set of
228
+ candidate functions when constructing an object of type *cv2* `D` if the
229
+ argument list has exactly one argument and `C` is reference-related to
230
+ `P` and `P` is reference-related to `D`.
231
 
232
  [*Example 3*:
233
 
234
  ``` cpp
235
  struct A {
 
252
 
253
  — *end example*]
254
 
255
  #### Function call syntax <a id="over.match.call">[[over.match.call]]</a>
256
 
257
+ ##### General <a id="over.match.call.general">[[over.match.call.general]]</a>
258
+
259
  In a function call [[expr.call]]
260
 
261
  ``` bnf
262
  postfix-expression '(' expression-listₒₚₜ ')'
263
  ```
 
267
  [[over.call.func]]. If the *postfix-expression* denotes an object of
268
  class type, overload resolution is applied as specified in
269
  [[over.call.object]].
270
 
271
  If the *postfix-expression* is the address of an overload set, overload
272
+ resolution is applied using that set as described above.
 
 
273
 
274
+ [*Note 1*: No implied object argument is added in this
275
+ case. — *end note*]
276
+
277
+ 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 named function <a id="over.call.func">[[over.call.func]]</a>
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 denotes one or more functions. Such a *postfix-expression*, perhaps
288
+ nested arbitrarily deep in parentheses, has one of the following forms:
 
289
 
290
  ``` bnf
291
  postfix-expression:
292
  postfix-expression '.' id-expression
293
  postfix-expression '->' id-expression
 
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 named by an *id-expression*
301
+ preceded by an `->` or `.` operator. Since the construct `A->B` is
302
+ generally equivalent to `(*A).B`, the rest of [[over]] assumes, without
303
+ loss of generality, that all member function calls have been normalized
304
+ to the form that uses an object and the `.` operator. Furthermore,
305
+ [[over]] assumes that the *postfix-expression* that is the left operand
306
+ of the `.` operator has type “cv `T`” where `T` denotes a class.[^2]
307
+
308
+ The function declarations found by name lookup [[class.member.lookup]]
309
+ constitute the set of candidate functions. The argument list is the
310
+ *expression-list* in the call augmented by the addition of the left
311
+ operand of the `.` operator in the normalized member function call as
312
+ the implied object argument [[over.match.funcs]].
313
+
314
+ In unqualified function calls, the function is named by a
315
+ *primary-expression*. The function declarations found by name lookup
316
+ [[basic.lookup]] constitute the set of candidate functions. Because of
317
+ the rules for name lookup, the set of candidate functions consists
318
+ either entirely of non-member functions or entirely of member functions
319
+ of some class `T`. In the former case or if the *primary-expression* is
320
+ the address of an overload set, the argument list is the same as the
321
+ *expression-list* in the call. Otherwise, the argument list is the
322
+ *expression-list* in the call augmented by the addition of an implied
323
+ object argument as in a qualified function call. If the current class
324
+ is, or is derived from, `T`, and the keyword `this` [[expr.prim.this]]
325
+ refers to it, then the implied object argument is `(*this)`. Otherwise,
326
+ a contrived object of type `T` becomes the implied object argument;[^3]
327
+
328
+ if overload resolution selects a non-static member function, the call is
329
+ ill-formed.
330
+
331
+ [*Example 1*:
332
+
333
+ ``` cpp
334
+ struct C {
335
+ void a();
336
+ void b() {
337
+ a(); // OK, (*this).a()
338
+ }
339
+
340
+ void c(this const C&); // #1
341
+ void c()&; // #2
342
+ static void c(int = 0); // #3
343
+
344
+ void d() {
345
+ c(); // error: ambiguous between #2 and #3
346
+ (C::c)(); // error: as above
347
+ (&(C::c))(); // error: cannot resolve address of overloaded this->C::c[over.over]
348
+ (&C::c)(C{}); // selects #1
349
+ (&C::c)(*this); // error: selects #2, and is ill-formed[over.match.call.general]
350
+ (&C::c)(); // selects #3
351
+ }
352
+
353
+ void f(this const C&);
354
+ void g() const {
355
+ f(); // OK, (*this).f()
356
+ f(*this); // error: no viable candidate for (*this).f(*this)
357
+ this->f(); // OK
358
+ }
359
+
360
+ static void h() {
361
+ f(); // error: contrived object argument, but overload resolution
362
+ // picked a non-static member function
363
+ f(C{}); // error: no viable candidate
364
+ C{}.f(); // OK
365
+ }
366
+
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
 
377
  ##### Call to object of class type <a id="over.call.object">[[over.call.object]]</a>
378
 
379
  If the *postfix-expression* `E` in the function call syntax evaluates to
380
  a class object of type “cv `T`”, then the set of candidate functions
381
  includes at least the function call operators of `T`. The function call
382
+ operators of `T` are the results of a search for the name `operator()`
383
+ in the scope of `T`.
384
 
385
  In addition, for each non-explicit conversion function declared in `T`
386
  of the form
387
 
388
  ``` bnf
 
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`
408
  provided the function is not hidden within `T` by another intervening
409
+ declaration.[^4]
410
 
411
  The argument list submitted to overload resolution consists of the
412
  argument expressions present in the function call syntax preceded by the
413
  implied object argument `(E)`.
414
 
415
+ [*Note 3*: When comparing the call against the function call operators,
416
+ the implied object argument is compared against the object parameter of
417
+ the function call operator. When comparing the call against a surrogate
418
+ call function, the implied object argument is compared against the first
419
+ parameter of the surrogate call function. — *end note*]
 
 
 
 
420
 
421
+ [*Example 2*:
422
 
423
  ``` cpp
424
  int f1(int);
425
  int f2(float);
426
  typedef int (*fp1)(int);
 
466
  ```
467
 
468
  — *end example*]
469
 
470
  If either operand has a type that is a class or an enumeration, a
471
+ user-defined operator function can be declared that implements this
472
  operator or a user-defined conversion can be necessary to convert the
473
  operand to a type that is appropriate for a built-in operator. In this
474
  case, overload resolution is used to determine which operator function
475
  or built-in operator is to be invoked to implement the operator.
476
  Therefore, the operator notation is first transformed to the equivalent
 
496
  operand of type *cv2* `T2`, four sets of candidate functions, designated
497
  *member candidates*, *non-member candidates*, *built-in candidates*, and
498
  *rewritten candidates*, are constructed as follows:
499
 
500
  - If `T1` is a complete class type or a class currently being defined,
501
+ the set of member candidates is the result of a search for `operator@`
502
+ in the scope of `T1`; otherwise, the set of member candidates is
503
+ empty.
504
+ - For the operators `=`, `[]`, or `->`, the set of non-member candidates
505
+ is empty; otherwise, it includes the result of unqualified lookup for
506
+ `operator@` in the rewritten function call
507
+ [[basic.lookup.unqual]], [[basic.lookup.argdep]], ignoring all member
508
+ functions. However, if no operand has a class type, only those
509
+ non-member functions in the lookup set that have a first parameter of
510
+ type `T1` or “reference to cv `T1`”, when `T1` is an enumeration type,
511
+ or (if there is a right operand) a second parameter of type `T2` or
512
  “reference to cv `T2`”, when `T2` is an enumeration type, are
513
  candidate functions.
514
  - For the operator `,`, the unary operator `&`, or the operator `->`,
515
  the built-in candidates set is empty. For all other operators, the
516
  built-in candidates include all of the candidate operator functions
 
518
  - have the same operator name, and
519
  - accept the same number of operands, and
520
  - accept operand types to which the given operand or operands can be
521
  converted according to [[over.best.ics]], and
522
  - do not have the same parameter-type-list as any non-member candidate
523
+ or rewritten non-member candidate that is not a function template
524
+ specialization.
525
  - The rewritten candidate set is determined as follows:
526
  - For the relational [[expr.rel]] operators, the rewritten candidates
527
  include all non-rewritten candidates for the expression `x <=> y`.
528
  - For the relational [[expr.rel]] and three-way comparison
529
  [[expr.spaceship]] operators, the rewritten candidates also include
530
  a synthesized candidate, with the order of the two parameters
531
  reversed, for each non-rewritten candidate for the expression
532
  `y <=> x`.
533
  - For the `!=` operator [[expr.eq]], the rewritten candidates include
534
+ all non-rewritten candidates for the expression `x == y` that are
535
+ rewrite targets with first operand `x` (see below).
536
  - For the equality operators, the rewritten candidates also include a
537
  synthesized candidate, with the order of the two parameters
538
  reversed, for each non-rewritten candidate for the expression
539
+ `y == x` that is a rewrite target with first operand `y`.
540
  - For all other operators, the rewritten candidate set is empty.
541
 
542
  \[*Note 2*: A candidate synthesized from a member candidate has its
543
+ object parameter as the second parameter, thus implicit conversions
544
+ are considered for the first, but not for the second,
545
  parameter. — *end note*]
546
 
547
+ A non-template function or function template `F` named `operator==` is a
548
+ rewrite target with first operand `o` unless a search for the name
549
+ `operator!=` in the scope S from the instantiation context of the
550
+ operator expression finds a function or function template that would
551
+ correspond [[basic.scope.scope]] to `F` if its name were `operator==`,
552
+ where S is the scope of the class type of `o` if `F` is a class member,
553
+ and the namespace scope of which `F` is a member otherwise. A function
554
+ template specialization named `operator==` is a rewrite target if its
555
+ function template is a rewrite target.
556
+
557
+ [*Example 2*:
558
+
559
+ ``` cpp
560
+ struct A {};
561
+ template<typename T> bool operator==(A, T); // #1
562
+ bool a1 = 0 == A(); // OK, calls reversed #1
563
+ template<typename T> bool operator!=(A, T);
564
+ bool a2 = 0 == A(); // error, #1 is not a rewrite target
565
+
566
+ struct B {
567
+ bool operator==(const B&); // #2
568
+ };
569
+ struct C : B {
570
+ C();
571
+ C(B);
572
+ bool operator!=(const B&); // #3
573
+ };
574
+ bool c1 = B() == C(); // OK, calls #2; reversed #2 is not a candidate
575
+ // because search for operator!= in C finds #3
576
+ bool c2 = C() == B(); // error: ambiguous between #2 found when searching C and
577
+ // reversed #2 found when searching B
578
+
579
+ struct D {};
580
+ template<typename T> bool operator==(D, T); // #4
581
+ inline namespace N {
582
+ template<typename T> bool operator!=(D, T); // #5
583
+ }
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, conversions of the left operand
590
  are restricted as follows:
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
 
600
  the built-in candidates, and the rewritten candidates for that operator
601
  `@`.
602
 
603
  The argument list contains all of the operands of the operator. The best
604
  function from the set of candidate functions is selected according to 
605
+ [[over.match.viable]] and  [[over.match.best]].[^5]
606
 
607
+ [*Example 3*:
608
 
609
  ``` cpp
610
  struct A {
611
  operator int();
612
  };
 
644
  conversion sequence of a user-defined conversion sequence
645
  [[over.ics.user]] is not applied. Then the operator is treated as the
646
  corresponding built-in operator and interpreted according to
647
  [[expr.compound]].
648
 
649
+ [*Example 4*:
650
 
651
  ``` cpp
652
  struct X {
653
  operator double();
654
  };
 
664
  — *end example*]
665
 
666
  The second operand of operator `->` is ignored in selecting an
667
  `operator->` function, and is not an argument when the `operator->`
668
  function is called. When `operator->` returns, the operator `->` is
669
+ applied to the value returned, with the original second operand.[^6]
670
 
671
  If the operator is the operator `,`, the unary operator `&`, or the
672
  operator `->`, and there are no viable functions, then the operator is
673
  assumed to be the built-in operator and interpreted according to
674
  [[expr.compound]].
 
690
 
691
  A a;
692
 
693
  void B::f() {
694
  operator+ (a,a); // error: global operator hidden by member
695
+ a + a; // OK, calls global operator+
696
  }
697
  ```
698
 
699
  — *end note*]
700
 
 
728
  with `T` a class type, the candidate functions are selected as follows:
729
 
730
  - The converting constructors [[class.conv.ctor]] of `T` are candidate
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
736
+ the first parameter of a constructor where the parameter is of type
737
+ “reference to *cv2* `T`” and the constructor is called with a single
738
+ argument in the context of direct-initialization of an object of type
739
+ “*cv3* `T`”, the permissible types for explicit conversion functions
740
+ are the same; otherwise there are none.
 
 
 
 
741
 
742
  In both cases, the argument list has one argument, which is the
743
  initializer expression.
744
 
745
  [*Note 2*: This argument will be compared against the first parameter
746
+ of the constructors and against the object parameter of the conversion
747
+ functions. — *end note*]
748
 
749
  #### Initialization by conversion function <a id="over.match.conv">[[over.match.conv]]</a>
750
 
751
  Under the conditions specified in  [[dcl.init]], as part of an
752
  initialization of an object of non-class type, a conversion function can
753
  be invoked to convert an initializer expression of class type to the
754
  type of the object being initialized. Overload resolution is used to
755
+ select the conversion function to be invoked. Assuming that “cv `T`” is
756
+ the type of the object being initialized, the candidate functions are
757
+ selected as follows:
 
758
 
759
+ - The permissible types for non-explicit conversion functions are those
760
+ that can be converted to type `T` via a standard conversion sequence
761
+ [[over.ics.scs]]. For direct-initialization, the permissible types for
762
+ explicit conversion functions are those that can be converted to type
763
+ `T` with a (possibly trivial) qualification conversion [[conv.qual]];
764
+ otherwise there are none.
 
 
 
 
 
 
 
765
 
766
  The argument list has one argument, which is the initializer expression.
767
 
768
+ [*Note 1*: This argument will be compared against the object parameter
769
+ of the conversion functions. — *end note*]
770
 
771
  #### Initialization by conversion function for direct reference binding <a id="over.match.ref">[[over.match.ref]]</a>
772
 
773
  Under the conditions specified in  [[dcl.init.ref]], a reference can be
774
  bound directly to the result of applying a conversion function to an
775
  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 initializing an lvalue
782
+ reference or an rvalue reference to function) and
783
+ - “*cv2* `T2`” and rvalue reference to *cv2* `T2`” (when initializing
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
790
+ functions are the members of R where `T2` can be converted to type `T`
791
+ with a (possibly trivial) qualification conversion [[conv.qual]];
792
+ otherwise there are none.
 
 
793
 
794
  The argument list has one argument, which is the initializer expression.
795
 
796
+ [*Note 1*: This argument will be compared against the object parameter
797
+ of the conversion functions. — *end note*]
798
 
799
  #### Initialization by list-initialization <a id="over.match.list">[[over.match.list]]</a>
800
 
801
  When objects of non-aggregate class type `T` are list-initialized such
802
  that [[dcl.init.list]] specifies that overload resolution is performed
 
815
  consists of the elements of the initializer list.
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 converting
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* names a primary
 
862
  of the *braced-init-list*, or of the *expression-list*. For each xᵢ, let
863
  eᵢ be the corresponding aggregate element of `C` or of one of its
864
  (possibly recursive) subaggregates that would be initialized by xᵢ
865
  [[dcl.init.aggr]] if
866
 
867
+ - brace elision is not considered for any aggregate element that has
868
+ - a dependent non-array type,
869
+ - an array type with a value-dependent bound, or
870
+ - an array type with a dependent array element type and xᵢ is a string
871
+ literal; and
872
  - each non-trailing aggregate element that is a pack expansion is
873
  assumed to correspond to no elements of the initializer list, and
874
  - a trailing aggregate element that is a pack expansion is assumed to
875
  correspond to all remaining elements of the initializer list (if any).
876
 
877
  If there is no such aggregate element eᵢ for any xᵢ, the aggregate
878
  deduction candidate is not added to the set. The aggregate deduction
879
  candidate is derived as above from a hypothetical constructor
880
  `C`(`T₁`, …, `Tₙ`), where
881
 
882
+ - if eᵢ is of array type and xᵢ is a *braced-init-list*, `Tᵢ` is an
883
+ rvalue reference to the declared type of eᵢ, and
884
+ - if eᵢ is of array type and xᵢ is a *string-literal*, `Tᵢ` is an lvalue
885
+ reference to the const-qualified declared type of eᵢ, and
886
  - otherwise, `Tᵢ` is the declared type of eᵢ,
887
 
888
  except that additional parameter packs of the form `Pⱼ` `...` are
889
  inserted into the parameter list in their original aggregate element
890
  position corresponding to each non-trailing aggregate element of type
891
  `Pⱼ` that was skipped because it was a parameter pack, and the trailing
892
  sequence of parameters corresponding to a trailing aggregate element
893
  that is a pack expansion (if any) is replaced by a single parameter of
894
+ the form `Tₙ` `...`. In addition, if `C` is defined and inherits
895
+ constructors [[namespace.udecl]] from a direct base class denoted in the
896
+ *base-specifier-list* by a *class-or-decltype* `B`, let `A` be an alias
897
+ template whose template parameter list is that of `C` and whose
898
+ *defining-type-id* is `B`. If `A` is a deducible template
899
+ [[dcl.type.simple]], the set contains the guides of `A` with the return
900
+ type `R` of each guide replaced with `typename CC<R>::type` given a
901
+ class template
902
+
903
+ ``` cpp
904
+ template <typename> class CC;
905
+ ```
906
+
907
+ whose primary template is not defined and with a single partial
908
+ 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 1*: Equivalently, the template parameter list of the
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*:
920
+
921
+ ``` cpp
922
+ template <typename T> struct B {
923
+ B(T);
924
+ };
925
+ template <typename T> struct C : public B<T> {
926
+ using B<T>::B;
927
+ };
928
+ template <typename T> struct D : public B<T> {};
929
+
930
+ C c(42); // OK, deduces C<int>
931
+ D d(42); // error: deduction failed, no inherited deduction guides
932
+ B(int) -> B<char>;
933
+ C c2(42); // OK, deduces C<char>
934
+
935
+ template <typename T> struct E : public B<int> {
936
+ using B<int>::B;
937
+ };
938
+
939
+ E e(42); // error: deduction failed, arguments of E cannot be deduced from introduced guides
940
+
941
+ template <typename T, typename U, typename V> struct F {
942
+ F(T, U, V);
943
+ };
944
+ template <typename T, typename U> struct G : F<U, T, int> {
945
+ using G::F::F;
946
+ }
947
+
948
+ G g(true, 'a', 1); // OK, deduces G<char, bool>
949
+
950
+ template<class T, std::size_t N>
951
+ struct H {
952
+ T array[N];
953
+ };
954
+ template<class T, std::size_t N>
955
+ struct I {
956
+ volatile T array[N];
957
+ };
958
+ template<std::size_t N>
959
+ struct J {
960
+ unsigned char array[N];
961
+ };
962
+
963
+ H h = { "abc" }; // OK, deduces H<char, 4> (not T = const char)
964
+ I i = { "def" }; // OK, deduces I<char, 4>
965
+ J j = { "ghi" }; // error: cannot bind reference to array of unsigned char to array of char in deduction
966
+ ```
967
+
968
+ — *end example*]
969
 
970
  When resolving a placeholder for a deduced class type
971
  [[dcl.type.simple]] where the *template-name* names an alias template
972
  `A`, the *defining-type-id* of `A` must be of the form
973
 
 
979
  functions or function templates formed as follows. For each function or
980
  function template `f` in the guides of the template named by the
981
  *simple-template-id* of the *defining-type-id*, the template arguments
982
  of the return type of `f` are deduced from the *defining-type-id* of `A`
983
  according to the process in [[temp.deduct.type]] with the exception that
984
+ deduction does not fail if not all template arguments are deduced. If
985
+ deduction fails for another reason, proceed with an empty set of deduced
986
+ template arguments. Let `g` denote the result of substituting these
987
+ deductions into `f`. If substitution succeeds, form a function or
988
+ function template `f'` with the following properties and add it to the
989
+ set of guides of `A`:
990
 
991
  - The function type of `f'` is the function type of `g`.
992
  - If `f` is a function template, `f'` is a function template whose
993
  template parameter list consists of all the template parameters of `A`
994
  (including their default template arguments) that appear in the above
 
998
  function template.
999
  - The associated constraints [[temp.constr.decl]] are the conjunction of
1000
  the associated constraints of `g` and a constraint that is satisfied
1001
  if and only if the arguments of `A` are deducible (see below) from the
1002
  return type.
1003
+ - If `f` is a copy deduction candidate, then `f'` is considered to be so
1004
+ as well.
1005
+ - If `f` was generated from a *deduction-guide* [[temp.deduct.guide]],
1006
+ then `f'` is considered to be so as well.
1007
  - The *explicit-specifier* of `f'` is the *explicit-specifier* of `g`
1008
  (if any).
1009
 
1010
  The arguments of a template `A` are said to be deducible from a type `T`
1011
  if, given a class template
 
1043
  *deduction-guide* that had an *explicit-specifier*, each such notional
1044
  constructor is considered to have that same *explicit-specifier*. All
1045
  such notional constructors are considered to be public members of the
1046
  hypothetical class type.
1047
 
1048
+ [*Example 2*:
1049
 
1050
  ``` cpp
1051
  template <class T> struct A {
1052
  explicit A(const T&, ...) noexcept; // #1
1053
  A(T&&, ...); // #2
 
1125
  F f3 = {Types<X, Y, Z>{}, X{}, W{}}; // error: conflicting types deduced; operator Y not considered
1126
  ```
1127
 
1128
  — *end example*]
1129
 
1130
+ [*Example 3*:
1131
 
1132
  ``` cpp
1133
  template <class T, class U> struct C {
1134
  C(T, U); // #1
1135
  };
 
1156
  template <class> class AA;
1157
  template <class V> class AA<A<V>> { };
1158
  template <class T> concept deduces_A = requires { sizeof(AA<T>); };
1159
 
1160
  // f1 is formed from the constructor #1 of C, generating the following function template
1161
+ template<class T, class U>
1162
  auto f1(T, U) -> C<T, U>;
1163
 
1164
  // Deducing arguments for C<T, U> from C<V *, V*> deduces T as V * and U as V *;
1165
  // f1' is obtained by transforming f1 as described by the above procedure.
1166
  template<class V> requires deduces_A<C<V *, V *>>
 
1204
  function parameters other than the ranking of conversion sequences.
1205
 
1206
  First, to be a viable function, a candidate function shall have enough
1207
  parameters to agree in number with the arguments in the list.
1208
 
1209
+ - If there are m arguments in the list, all candidate functions having
1210
+ exactly m parameters are viable.
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 if
1217
  all parameters following the mᵗʰ have default arguments
1218
  [[dcl.fct.default]]. For the purposes of overload resolution, the
1219
+ parameter list is truncated on the right, so that there are exactly m
1220
+ parameters.
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
 
1226
  Third, for `F` to be a viable function, there shall exist for each
1227
  argument an implicit conversion sequence [[over.best.ics]] that converts
1228
  that argument to the corresponding parameter of `F`. If the parameter
1229
  has reference type, the implicit conversion sequence includes the
1230
  operation of binding the reference, and the fact that an lvalue
1231
+ reference to non-`const` cannot bind to an rvalue and that an rvalue
1232
+ reference cannot bind to an lvalue can affect the viability of the
1233
  function (see  [[over.ics.ref]]).
1234
 
1235
  ### Best viable function <a id="over.match.best">[[over.match.best]]</a>
1236
 
1237
+ #### General <a id="over.match.best.general">[[over.match.best.general]]</a>
1238
 
1239
+ Define ICS(`F`) as the implicit conversion sequence that converts the
1240
+ iᵗʰ argument in the list to the type of the iᵗʰ parameter of viable
1241
+ function `F`. [[over.best.ics]] defines the implicit conversion
 
 
 
 
1242
  sequences and [[over.ics.rank]] defines what it means for one implicit
1243
  conversion sequence to be a better conversion sequence or worse
1244
  conversion sequence than another.
1245
 
1246
+ Given these definitions, a viable function `F₁` is defined to be a
1247
+ *better* function than another viable function `F₂` if for all arguments
1248
+ i, ICS(`F₁`) is not a worse conversion sequence than ICS(`F₂`), and
1249
+ 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 return type of `F₁` to 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 return type of `F₂` to the destination type
1259
  \[*Example 1*:
1260
  ``` cpp
1261
  struct A {
1262
  A();
1263
  operator int();
 
1300
  parameter-type-lists, and `F1` is more constrained than `F2` according
1301
  to the partial ordering of constraints described in
1302
  [[temp.constr.order]], or if not that,
1303
  - `F1` is a constructor for a class `D`, `F2` is a constructor for a
1304
  base class `B` of `D`, and for all arguments the corresponding
1305
+ parameters of `F1` and `F2` have the same type
1306
  \[*Example 3*:
1307
  ``` cpp
1308
  struct A {
1309
  A(int = 0);
1310
  };
 
1344
  bool b = 1 < S(); // calls #2
1345
  ```
1346
 
1347
  — *end example*]
1348
  or, if not that
1349
+ - `F1` and `F2` are generated from class template argument deduction
1350
+ [[over.match.class.deduct]] for a class `D`, and `F2` is generated
1351
+ from inheriting constructors from a base class of `D` while `F1` is
1352
+ not, and for each explicit function argument, the corresponding
1353
+ parameters of `F1` and `F2` are either both ellipses or have the same
1354
+ type, or, if not that,
1355
  - `F1` is generated from a *deduction-guide* [[over.match.class.deduct]]
1356
  and `F2` is not, or, if not that,
1357
  - `F1` is the copy deduction candidate [[over.match.class.deduct]] and
1358
  `F2` is not, or, if not that,
1359
  - `F1` is generated from a non-template constructor and `F2` is
 
1386
 
1387
  — *end example*]
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 7*:
1394
 
1395
  ``` cpp
1396
  void Fcn(const int*, short);
 
1405
 
1406
  Fcn(&i, 1L); // calls Fcn(int*, int), because &i → int* is better than &i → const int*
1407
  // and 1L → short and 1L → int are indistinguishable
1408
 
1409
  Fcn(&i, 'c'); // calls Fcn(int*, int), because &i → int* is better than &i → const int*
1410
+ // and 'c' → int is better than 'c' → short
1411
  }
1412
  ```
1413
 
1414
  — *end example*]
1415
 
1416
  If the best viable function resolves to a function for which multiple
1417
+ declarations were found, and if any two of these declarations inhabit
1418
+ different scopes and specify a default argument that made the function
1419
+ viable, the program is ill-formed.
 
1420
 
1421
  [*Example 8*:
1422
 
1423
  ``` cpp
1424
  namespace A {
 
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
+
1446
  An *implicit conversion sequence* is a sequence of conversions used to
1447
  convert an argument in a function call to the type of the corresponding
1448
  parameter of the function being called. The sequence of conversions is
1449
  an implicit conversion as defined in [[conv]], which means it is
1450
  governed by the rules for initialization of an object or reference by a
1451
+ 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
 
 
1470
  - an ellipsis conversion sequence [[over.ics.ellipsis]].
1471
 
1472
  However, if the target is
1473
 
1474
  - the first parameter of a constructor or
1475
+ - the object parameter of a user-defined conversion function
1476
 
1477
  and the constructor or user-defined conversion function is a candidate
1478
  by
1479
 
1480
  - [[over.match.ctor]], when the argument is the temporary in the second
 
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 converting to the explicit object parameter, if any,
1553
+ user-defined conversion sequences are allowed. — *end note*]
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
 
1559
  If no sequence of conversions can be found to convert an argument to a
 
1566
  the purpose of ranking implicit conversion sequences as described in 
1567
  [[over.ics.rank]], the ambiguous conversion sequence is treated as a
1568
  user-defined conversion sequence that is indistinguishable from any
1569
  other user-defined conversion sequence.
1570
 
1571
+ [*Note 6*:
1572
 
1573
  This rule prevents a function from becoming non-viable because of an
1574
  ambiguous conversion sequence for one of its parameters.
1575
 
1576
  [*Example 3*:
 
1604
 
1605
  summarizes the conversions defined in [[conv]] and partitions them into
1606
  four disjoint categories: Lvalue Transformation, Qualification
1607
  Adjustment, Promotion, and Conversion.
1608
 
1609
+ [*Note 7*: These categories are orthogonal with respect to value
1610
  category, cv-qualification, and data representation: the Lvalue
1611
  Transformations do not change the cv-qualification or data
1612
  representation of the type; the Qualification Adjustments do not change
1613
  the value category or data representation of the type; and the
1614
  Promotions and Conversions do not change the value category or
1615
  cv-qualification of the type. — *end note*]
1616
 
1617
+ [*Note 8*: As described in [[conv]], a standard conversion sequence
1618
  either is the Identity conversion by itself (that is, no conversion) or
1619
  consists of one to three conversions from the other four categories. If
1620
  there are two or more conversions in the sequence, the conversions are
1621
  applied in the canonical order: **Lvalue Transformation**, **Promotion**
1622
  or **Conversion**, **Qualification Adjustment**. — *end note*]
 
1644
  A *user-defined conversion sequence* consists of an initial standard
1645
  conversion sequence followed by a user-defined conversion [[class.conv]]
1646
  followed by a second standard conversion sequence. If the user-defined
1647
  conversion is specified by a constructor [[class.conv.ctor]], the
1648
  initial standard conversion sequence converts the source type to the
1649
+ type of the first parameter of that constructor. If the user-defined
1650
  conversion is specified by a conversion function [[class.conv.fct]], the
1651
  initial standard conversion sequence converts the source type to the
1652
+ type of the object parameter of that conversion function.
1653
 
1654
  The second standard conversion sequence converts the result of the
1655
  user-defined conversion to the target type for the sequence; any
1656
  reference binding is included in the second standard conversion
1657
  sequence. Since an implicit conversion sequence is an initialization,
 
1679
 
1680
  When a parameter of reference type binds directly [[dcl.init.ref]] to an
1681
  argument expression, the implicit conversion sequence is the identity
1682
  conversion, unless the argument expression has a type that is a derived
1683
  class of the parameter type, in which case the implicit conversion
1684
+ sequence is a derived-to-base conversion [[over.best.ics]].
1685
 
1686
  [*Example 4*:
1687
 
1688
  ``` cpp
1689
  struct A {};
 
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 either an identity conversion or, if the
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
 
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 other than a function 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
1723
  lvalue reference (see  [[dcl.init.ref]]). — *end note*]
1724
 
 
1746
  initialized from the initializer list according to the rules for
1747
  aggregate initialization [[dcl.init.aggr]], in which case the implicit
1748
  conversion sequence is a user-defined conversion sequence whose second
1749
  standard conversion sequence is an identity conversion.
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
1755
  match for the selected overload, the initialization of the parameter
1756
  will be ill-formed [[dcl.init.list]].
 
1779
  Otherwise, if the parameter type is an aggregate class `X` and the
1780
  initializer list has a single element of type cv `U`, where `U` is `X`
1781
  or a class derived from `X`, the implicit conversion sequence is the one
1782
  required to convert the element to the parameter type.
1783
 
1784
+ Otherwise, if the parameter type is a character array[^8]
1785
+
1786
+ and the initializer list has a single element that is an
1787
+ appropriately-typed *string-literal* [[dcl.init.string]], the implicit
1788
+ conversion sequence is the identity conversion.
1789
 
1790
  Otherwise, if the parameter type is `std::initializer_list<X>` and all
1791
  the elements of the initializer list can be implicitly converted to `X`,
1792
  the implicit conversion sequence is the worst conversion necessary to
1793
  convert an element of the list to `X`, or if the initializer list has no
 
1797
 
1798
  [*Example 7*:
1799
 
1800
  ``` cpp
1801
  void f(std::initializer_list<int>);
1802
+ f( {} ); // OK, f(initializer_list<int>) identity conversion
1803
+ f( {1,2,3} ); // OK, f(initializer_list<int>) identity conversion
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>>); // #2
 
1814
  void g(A);
1815
  g({ "foo", "bar" }); // OK, uses #3
1816
 
1817
  typedef int IA[3];
1818
  void h(const IA&);
1819
+ h({ 1, 2, 3 }); // OK, identity conversion
1820
  ```
1821
 
1822
  — *end example*]
1823
 
1824
  Otherwise, if the parameter type is “array of `N` `X`” or “array of
 
1836
  - If `C` is not an initializer-list constructor and the initializer list
1837
  has a single element of type cv `U`, where `U` is `X` or a class
1838
  derived from `X`, the implicit conversion sequence has Exact Match
1839
  rank if `U` is `X`, or Conversion rank if `U` is derived from `X`.
1840
  - Otherwise, the implicit conversion sequence is a user-defined
1841
+ conversion sequence whose second standard conversion sequence is an
1842
  identity conversion.
1843
 
1844
  If multiple constructors are viable but none is better than the others,
1845
  the implicit conversion sequence is the ambiguous conversion sequence.
1846
  User-defined conversions are allowed for conversion of the initializer
 
1852
  ``` cpp
1853
  struct A {
1854
  A(std::initializer_list<int>);
1855
  };
1856
  void f(A);
1857
+ f( {'a', 'b'} ); // OK, f(A(std::initializer_list<int>)) user-defined conversion
1858
 
1859
  struct B {
1860
  B(int, double);
1861
  };
1862
  void g(B);
1863
+ g( {'a', 'b'} ); // OK, g(B(int, double)) user-defined conversion
1864
  g( {1.0, 1.0} ); // error: narrowing
1865
 
1866
  void f(B);
1867
  f( {'a', 'b'} ); // error: ambiguous f(A) or f(B)
1868
 
1869
  struct C {
1870
  C(std::string);
1871
  };
1872
  void h(C);
1873
+ h({"foo"}); // OK, h(C(std::string("foo")))
1874
 
1875
  struct D {
1876
  D(A, C);
1877
  };
1878
  void i(D);
1879
+ i({ {1,2}, {"bar"} }); // OK, i(D(A(std::initializer_list<int>{1,2\), C(std::string("bar"))))}
1880
  ```
1881
 
1882
  — *end example*]
1883
 
1884
  Otherwise, if the parameter has an aggregate type which can be
1885
  initialized from the initializer list according to the rules for
1886
  aggregate initialization [[dcl.init.aggr]], the implicit conversion
1887
+ sequence is a user-defined conversion sequence whose second standard
1888
+ conversion sequence is an identity conversion.
1889
 
1890
  [*Example 9*:
1891
 
1892
  ``` cpp
1893
  struct A {
1894
  int m1;
1895
  double m2;
1896
  };
1897
 
1898
  void f(A);
1899
+ f( {'a', 'b'} ); // OK, f(A(int,double)) user-defined conversion
1900
  f( {1.0} ); // error: narrowing
1901
  ```
1902
 
1903
  — *end example*]
1904
 
1905
  Otherwise, if the parameter is a reference, see  [[over.ics.ref]].
1906
 
1907
+ [*Note 11*: The rules in this subclause will apply for initializing the
1908
  underlying temporary for the reference. — *end note*]
1909
 
1910
  [*Example 10*:
1911
 
1912
  ``` cpp
 
1914
  int m1;
1915
  double m2;
1916
  };
1917
 
1918
  void f(const A&);
1919
+ f( {'a', 'b'} ); // OK, f(A(int,double)) user-defined conversion
1920
  f( {1.0} ); // error: narrowing
1921
 
1922
  void g(const double &);
1923
  g({1}); // same conversion as int to double
1924
  ```
 
1931
  initializer list, the implicit conversion sequence is the one required
1932
  to convert the element to the parameter type;
1933
  \[*Example 11*:
1934
  ``` cpp
1935
  void f(int);
1936
+ f( {'a'} ); // OK, same conversion as char to int
1937
  f( {1.0} ); // error: narrowing
1938
  ```
1939
 
1940
  — *end example*]
1941
  - if the initializer list has no elements, the implicit conversion
1942
  sequence is the identity conversion.
1943
  \[*Example 12*:
1944
  ``` cpp
1945
  void f(int);
1946
+ f( { } ); // OK, identity conversion
1947
  ```
1948
 
1949
  — *end example*]
1950
 
1951
  In all cases other than those enumerated above, no conversion is
 
2134
  - A conversion that does not convert a pointer or a pointer to member to
2135
  `bool` is better than one that does.
2136
  - A conversion that promotes an enumeration whose underlying type is
2137
  fixed to its underlying type is better than one that promotes to the
2138
  promoted underlying type, if the two are different.
2139
+ - A conversion in either direction between floating-point type `FP1` and
2140
+ floating-point type `FP2` is better than a conversion in the same
2141
+ direction between `FP1` and arithmetic type `T3` if
2142
+ - the floating-point conversion rank [[conv.rank]] of `FP1` is equal
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 8*:
2149
+ ``` cpp
2150
+ int f(std::float32_t);
2151
+ int f(std::float64_t);
2152
+ int f(long long);
2153
+ float x;
2154
+ std::float16_t y;
2155
+ int i = f(x); // calls f(std::float32_t) on implementations where
2156
+ // float and std::float32_t have equal conversion ranks
2157
+ int j = f(y); // error: ambiguous, no equal conversion rank
2158
+ ```
2159
+
2160
+ — *end example*]
2161
  - If class `B` is derived directly or indirectly from class `A`,
2162
  conversion of `B*` to `A*` is better than conversion of `B*` to
2163
  `void*`, and conversion of `A*` to `void*` is better than conversion
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 9*:
2170
  ``` cpp
2171
  struct A {};
2172
  struct B : public A {};
2173
  struct C : public B {};
2174
  C* pc;
 
2197
  types only in the context of comparing the second standard conversion
2198
  sequence of an initialization by user-defined conversion (see 
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 *id-expression* whose terminal name refers to an overload set S and
2205
+ that appears without arguments is resolved to a function, a pointer to
2206
+ function, or a pointer to member function for a specific function that
2207
+ is chosen from a set of functions selected from S determined based on
2208
+ the target type required in the context (if any), as described below.
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.ass]],
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 non-type *template-parameter* [[temp.arg.nontype]].
2221
 
2222
+ The *id-expression* can be preceded by the `&` operator.
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.
 
2230
  the function pointer conversion [[conv.fctptr]]) is identical to `FT`.
2231
 
2232
  [*Note 2*: That is, the class of which the function is a member is
2233
  ignored when matching a pointer-to-member-function type. — *end note*]
2234
 
2235
+ The specialization, if any, generated by template argument deduction
2236
+ [[temp.over]], [[temp.deduct.funcaddr]], [[temp.arg.explicit]] for each
2237
+ function template named is added to the set of selected functions
2238
+ considered.
 
2239
 
2240
+ Non-member functions, static member functions, and explicit object
2241
+ member functions match targets of function pointer type or reference to
2242
+ function type. Implicit object member functions match targets of
2243
+ pointer-to-member-function type.
 
 
 
2244
 
2245
+ [*Note 3*: If an implicit object member function is chosen, the result
2246
+ can be used only to form a pointer to member
2247
+ [[expr.unary.op]]. *end note*]
 
 
 
2248
 
2249
  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
 
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*:
2304
 
2305
  Even if `B` is a public base of `D`, we have
2306
 
 
2314
 
2315
  — *end note*]
2316
 
2317
  ## Overloaded operators <a id="over.oper">[[over.oper]]</a>
2318
 
2319
+ ### General <a id="over.oper.general">[[over.oper.general]]</a>
2320
+
2321
+ A declaration whose *declarator-id* is an *operator-function-id* shall
2322
+ declare a function or function template or an explicit instantiation or
2323
+ specialization of a function template. A function so declared is an
2324
+ *operator function*. A function template so declared is an *operator
2325
+ function template*. A specialization of an operator function template is
2326
+ also an operator function. An operator function is said to *implement*
2327
+ the operator named in its *operator-function-id*.
2328
 
2329
  ``` bnf
2330
  operator-function-id:
2331
  operator operator
2332
  ```
 
2382
  — *end example*]
2383
 
2384
  The allocation and deallocation functions, `operator` `new`, `operator`
2385
  `new[]`, `operator` `delete`, and `operator` `delete[]`, are described
2386
  completely in  [[basic.stc.dynamic]]. The attributes and restrictions
2387
+ found in the rest of [[over.oper]] do not apply to them unless
2388
  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 either
2395
+
2396
+ - be a member function or
2397
+ - be a non-member function that has at least one non-object parameter
2398
+ whose type is a class, a reference to a class, an enumeration, or a
2399
+ reference to an enumeration.
2400
+
2401
+ It is not possible to change the precedence, grouping, or number of
2402
+ operands of operators. The meaning of the operators `=`, (unary) `&`,
2403
+ and `,` (comma), predefined for each type, can be changed for specific
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
 
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.ass]] through 
2426
  [[over.inc]] act as ordinary unary and binary operators obeying the
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
2433
+ non-static member function [[class.mfct]] with no non-object parameters
2434
+ or a non-member function with one parameter. For a *unary-expression* of
2435
+ the form `@ cast-expression`, the operator function is selected by
2436
+ overload resolution [[over.match.oper]]. If a member function is
2437
+ selected, the expression is interpreted as
2438
 
2439
  ``` bnf
2440
  cast-expression '.' operator '@' '('')'
2441
  ```
2442
 
 
2445
 
2446
  ``` bnf
2447
  operator '@' '(' cast-expression ')'
2448
  ```
2449
 
2450
+ [*Note 1*: The operators `++` and `--` [[expr.pre.incr]] are described
2451
+ in  [[over.inc]]. — *end note*]
2452
 
2453
+ [*Note 2*: The unary and binary forms of the same operator have the
2454
+ same name. Consequently, a unary operator can hide a binary operator
 
 
2455
  from an enclosing scope, and vice versa. — *end note*]
2456
 
2457
  ### Binary operators <a id="over.binary">[[over.binary]]</a>
2458
 
2459
+ #### General <a id="over.binary.general">[[over.binary.general]]</a>
2460
+
2461
  A *binary operator function* is a function named `operator@` for a
2462
  binary operator `@` that is either a non-static member function
2463
+ [[class.mfct]] with one non-object parameter or a non-member function
2464
+ with two parameters. For an expression `x @ y` with subexpressions x and
2465
+ y, the operator function is selected by overload resolution
2466
  [[over.match.oper]]. If a member function is selected, the expression is
2467
  interpreted as
2468
 
2469
  ``` bnf
2470
  x '.' operator '@' '(' y ')'
 
2539
  — *end note*]
2540
 
2541
  ### Function call <a id="over.call">[[over.call]]</a>
2542
 
2543
  A *function call operator function* is a function named `operator()`
2544
+ that is a member function with an arbitrary number of parameters. It may
2545
+ have default arguments. For an expression of the form
2546
 
2547
  ``` bnf
2548
  postfix-expression '(' expression-listₒₚₜ ')'
2549
  ```
2550
 
2551
  where the *postfix-expression* is of class type, the operator function
2552
  is selected by overload resolution [[over.call.object]]. If a surrogate
2553
+ call function is selected, let e be the result of invoking the
2554
+ corresponding conversion operator function on the *postfix-expression*;
2555
+
2556
+ the expression is interpreted as
2557
 
2558
  ``` bnf
2559
+ e '(' expression-listₒₚₜ ')'
2560
  ```
2561
 
2562
  Otherwise, the expression is interpreted as
2563
 
2564
  ``` bnf
2565
  postfix-expression '.' operator '('')' '(' expression-listₒₚₜ ')'
2566
  ```
2567
 
2568
  ### Subscripting <a id="over.sub">[[over.sub]]</a>
2569
 
2570
+ A *subscripting operator function* is a member function named
2571
+ `operator[]` with an arbitrary number of parameters. It may have default
2572
+ arguments. For an expression of the form
2573
 
2574
  ``` bnf
2575
+ postfix-expression '[' expression-listₒₚₜ ']'
2576
  ```
2577
 
2578
  the operator function is selected by overload resolution
2579
  [[over.match.oper]]. If a member function is selected, the expression is
2580
  interpreted as
2581
 
2582
  ``` bnf
2583
+ postfix-expression . operator '['']' '(' expression-listₒₚₜ ')'
2584
  ```
2585
 
2586
  [*Example 1*:
2587
 
2588
  ``` cpp
2589
  struct X {
2590
  Z operator[](std::initializer_list<int>);
2591
+ Z operator[](auto...);
2592
  };
2593
  X x;
2594
+ x[{1,2,3}] = 7; // OK, meaning x.operator[]({1,2,3\)}
2595
+ x[1,2,3] = 7; // OK, meaning x.operator[](1,2,3)
2596
  int a[10];
2597
  a[{1,2,3}] = 7; // error: built-in subscript operator
2598
+ a[1,2,3] = 7; // error: built-in subscript operator
2599
  ```
2600
 
2601
  — *end example*]
2602
 
2603
  ### Class member access <a id="over.ref">[[over.ref]]</a>
2604
 
2605
  A *class member access operator function* is a function named
2606
+ `operator->` that is a non-static member function taking no non-object
2607
+ parameters. For an expression of the form
2608
 
2609
  ``` bnf
2610
  postfix-expression '->' templateₒₚₜ id-expression
2611
  ```
2612
 
 
2618
  ```
2619
 
2620
  ### Increment and decrement <a id="over.inc">[[over.inc]]</a>
2621
 
2622
  An *increment operator function* is a function named `operator++`. If
2623
+ this function is a non-static member function with no non-object
2624
+ parameters, or a non-member function with one parameter, it defines the
2625
+ prefix increment operator `++` for objects of that type. If the function
2626
+ is a non-static member function with one non-object parameter (which
2627
+ shall be of type `int`) or a non-member function with two parameters
2628
+ (the second of which shall be of type `int`), it defines the postfix
2629
+ increment operator `++` for objects of that type. When the postfix
2630
+ increment is called as a result of using the `++` operator, the `int`
2631
+ argument will have value zero.[^9]
2632
 
2633
  [*Example 1*:
2634
 
2635
  ``` cpp
2636
  struct X {
 
2655
  }
2656
  ```
2657
 
2658
  — *end example*]
2659
 
2660
+ A *decrement operator function* is a function named `operator--` and is
2661
+ handled analogously to an increment operator function.
2662
 
2663
  ## Built-in operators <a id="over.built">[[over.built]]</a>
2664
 
2665
  The candidate operator functions that represent the built-in operators
2666
  defined in [[expr.compound]] are specified in this subclause. These
 
2678
  that some of the candidate operator functions given in this subclause
2679
  are more permissive than the built-in operators themselves. As described
2680
  in  [[over.match.oper]], after a built-in operator is selected by
2681
  overload resolution the expression is subject to the requirements for
2682
  the built-in operator given in [[expr.compound]], and therefore to any
2683
+ additional semantic constraints given there. In some cases, user-written
2684
+ candidates with the same name and parameter types as a built-in
2685
+ candidate operator function cause the built-in operator function to not
2686
+ be included in the set of candidate functions. — *end note*]
2687
 
2688
  In this subclause, the term *promoted integral type* is used to refer to
2689
+ those cv-unqualified integral types which are preserved by integral
2690
+ promotion [[conv.prom]] (including e.g. `int` and `long` but excluding
2691
+ e.g. `char`).
2692
 
2693
  [*Note 2*: In all cases where a promoted integral type is required, an
2694
  operand of unscoped enumeration type will be acceptable by way of the
2695
  integral promotions. — *end note*]
2696
 
2697
  In the remainder of this subclause, *vq* represents either `volatile` or
2698
  no cv-qualifier.
2699
 
2700
+ For every pair (`T`, *vq*), where `T` is a cv-unqualified arithmetic
2701
+ type other than `bool` or a cv-unqualified pointer to (possibly
2702
+ cv-qualified) object type, there exist candidate operator functions of
2703
+ the form
2704
 
2705
  ``` cpp
2706
  vq T& operator++(vq T&);
2707
  T operator++(vq T&, int);
 
 
 
 
 
 
2708
  vq T& operator--(vq T&);
2709
  T operator--(vq T&, int);
2710
  ```
2711
 
2712
+ For every (possibly cv-qualified) object type `T` and for every function
2713
+ type `T` that has neither *cv-qualifier*s nor a *ref-qualifier*, there
2714
+ exist candidate operator functions of the form
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2715
 
2716
  ``` cpp
2717
  T& operator*(T*);
2718
  ```
2719
 
 
2721
 
2722
  ``` cpp
2723
  T* operator+(T*);
2724
  ```
2725
 
2726
+ For every cv-unqualified floating-point or promoted integral type `T`,
2727
+ there exist candidate operator functions of the form
2728
 
2729
  ``` cpp
2730
  T operator+(T);
2731
  T operator-(T);
2732
  ```
 
2931
 
2932
  The *string-literal* or *user-defined-string-literal* in a
2933
  *literal-operator-id* shall have no *encoding-prefix* and shall contain
2934
  no characters other than the implicit terminating `'\0'`. The
2935
  *ud-suffix* of the *user-defined-string-literal* or the *identifier* in
2936
+ a *literal-operator-id* is called a *literal suffix identifier*. The
2937
+ first form of *literal-operator-id* is deprecated [[depr.lit]]. Some
2938
  literal suffix identifiers are reserved for future standardization; see 
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
2944
+ could be a friend function [[class.friend]]) or an explicit
2945
+ instantiation or specialization of a function template. A function
2946
+ declared with a *literal-operator-id* is a *literal operator*. A
2947
+ function template declared with a *literal-operator-id* is a *literal
2948
+ operator template*.
2949
 
2950
  The declaration of a literal operator shall have a
2951
  *parameter-declaration-clause* equivalent to one of the following:
2952
 
2953
  ``` cpp
 
2989
  invoked implicitly through user-defined literals [[lex.ext]]. However,
2990
  except for the constraints described above, they are ordinary
2991
  namespace-scope functions and function templates. In particular, they
2992
  are looked up like ordinary functions and function templates and they
2993
  follow the same overload resolution rules. Also, they can be declared
2994
+ `inline` or `constexpr`, they can have internal, module, or external
2995
  linkage, they can be called explicitly, their addresses can be taken,
2996
  etc. — *end note*]
2997
 
2998
  [*Example 1*:
2999
 
3000
  ``` cpp
3001
  void operator ""_km(long double); // OK
3002
+ string operator "" _i18n(const char*, std::size_t); // OK, deprecated
3003
+ template <char...> double operator ""_\u03C0(); // OK, UCN for lowercase pi
3004
  float operator ""_e(const char*); // OK
3005
+ float operator ""E(const char*); // ill-formed, no diagnostic required:
3006
+ // reserved literal suffix[usrlit.suffix,lex.ext]
3007
+ double operator""_Bq(long double); // OK, does not use the reserved identifier _Bq[lex.name]
3008
+ double operator"" _Bq(long double); // ill-formed, no diagnostic required:
3009
+ // uses the reserved identifier _Bq[lex.name]
3010
  float operator " "B(const char*); // error: non-empty string-literal
3011
  string operator ""5X(const char*, std::size_t); // error: invalid literal suffix identifier
3012
  double operator ""_miles(double); // error: invalid parameter-declaration-clause
3013
  template <char...> int operator ""_j(const char*); // error: invalid parameter-declaration-clause
3014
  extern "C" void operator ""_m(long double); // error: C language linkage
 
3017
  — *end example*]
3018
 
3019
  <!-- Link reference definitions -->
3020
  [basic.lookup]: basic.md#basic.lookup
3021
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
3022
+ [basic.lookup.unqual]: basic.md#basic.lookup.unqual
3023
+ [basic.scope.scope]: basic.md#basic.scope.scope
3024
  [basic.stc.dynamic]: basic.md#basic.stc.dynamic
3025
  [class.access]: class.md#class.access
3026
  [class.conv]: class.md#class.conv
3027
  [class.conv.ctor]: class.md#class.conv.ctor
3028
  [class.conv.fct]: class.md#class.conv.fct
3029
  [class.copy.assign]: class.md#class.copy.assign
3030
  [class.copy.ctor]: class.md#class.copy.ctor
3031
  [class.friend]: class.md#class.friend
3032
  [class.inhctor.init]: class.md#class.inhctor.init
3033
  [class.mem]: class.md#class.mem
3034
+ [class.member.lookup]: basic.md#class.member.lookup
3035
  [class.mfct]: class.md#class.mfct
 
 
3036
  [conv]: expr.md#conv
3037
  [conv.array]: expr.md#conv.array
3038
  [conv.bool]: expr.md#conv.bool
3039
  [conv.double]: expr.md#conv.double
3040
  [conv.fctptr]: expr.md#conv.fctptr
 
3045
  [conv.lval]: expr.md#conv.lval
3046
  [conv.mem]: expr.md#conv.mem
3047
  [conv.prom]: expr.md#conv.prom
3048
  [conv.ptr]: expr.md#conv.ptr
3049
  [conv.qual]: expr.md#conv.qual
3050
+ [conv.rank]: basic.md#conv.rank
3051
  [cpp.concat]: cpp.md#cpp.concat
3052
  [cpp.stringize]: cpp.md#cpp.stringize
 
 
3053
  [dcl.fct]: dcl.md#dcl.fct
3054
  [dcl.fct.def.delete]: dcl.md#dcl.fct.def.delete
3055
  [dcl.fct.default]: dcl.md#dcl.fct.default
3056
  [dcl.fct.spec]: dcl.md#dcl.fct.spec
3057
  [dcl.init]: dcl.md#dcl.init
 
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.ass]: expr.md#expr.ass
3067
  [expr.await]: expr.md#expr.await
3068
  [expr.call]: expr.md#expr.call
3069
  [expr.cast]: expr.md#expr.cast
 
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
 
3083
  [lex.ext]: lex.md#lex.ext
3084
  [namespace.udecl]: dcl.md#namespace.udecl
3085
  [over]: #over
3086
  [over.ass]: #over.ass
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
3092
  [over.call]: #over.call
3093
  [over.call.func]: #over.call.func
3094
  [over.call.object]: #over.call.object
 
3095
  [over.ics.ellipsis]: #over.ics.ellipsis
3096
  [over.ics.list]: #over.ics.list
3097
  [over.ics.rank]: #over.ics.rank
3098
  [over.ics.ref]: #over.ics.ref
3099
  [over.ics.scs]: #over.ics.scs
3100
  [over.ics.user]: #over.ics.user
3101
  [over.inc]: #over.inc
3102
  [over.literal]: #over.literal
 
3103
  [over.match]: #over.match
3104
  [over.match.best]: #over.match.best
3105
+ [over.match.best.general]: #over.match.best.general
3106
  [over.match.call]: #over.match.call
3107
+ [over.match.call.general]: #over.match.call.general
3108
  [over.match.class.deduct]: #over.match.class.deduct
3109
  [over.match.conv]: #over.match.conv
3110
  [over.match.copy]: #over.match.copy
3111
  [over.match.ctor]: #over.match.ctor
3112
  [over.match.funcs]: #over.match.funcs
3113
+ [over.match.funcs.general]: #over.match.funcs.general
3114
+ [over.match.general]: #over.match.general
3115
  [over.match.list]: #over.match.list
3116
  [over.match.oper]: #over.match.oper
3117
  [over.match.ref]: #over.match.ref
3118
  [over.match.viable]: #over.match.viable
3119
  [over.oper]: #over.oper
3120
+ [over.oper.general]: #over.oper.general
3121
  [over.over]: #over.over
3122
  [over.pre]: #over.pre
3123
  [over.ref]: #over.ref
3124
  [over.sub]: #over.sub
3125
  [over.unary]: #over.unary
 
3129
  [temp.constr.constr]: temp.md#temp.constr.constr
3130
  [temp.constr.decl]: temp.md#temp.constr.decl
3131
  [temp.constr.order]: temp.md#temp.constr.order
3132
  [temp.deduct]: temp.md#temp.deduct
3133
  [temp.deduct.funcaddr]: temp.md#temp.deduct.funcaddr
3134
+ [temp.deduct.guide]: temp.md#temp.deduct.guide
3135
  [temp.deduct.type]: temp.md#temp.deduct.type
3136
  [temp.dep]: temp.md#temp.dep
3137
  [temp.dep.type]: temp.md#temp.dep.type
3138
  [temp.func.order]: temp.md#temp.func.order
3139
  [temp.over]: temp.md#temp.over
 
3140
  [temp.variadic]: temp.md#temp.variadic
3141
  [usrlit.suffix]: library.md#usrlit.suffix
3142
 
3143
+ [^1]: The process of argument deduction fully determines the parameter
 
 
 
 
 
 
3144
  types of the function template specializations, i.e., the parameters
3145
  of function template specializations contain no template parameter
3146
  types. Therefore, except where specified otherwise, function
3147
  template specializations and non-template functions [[dcl.fct]] are
3148
  treated equivalently for the remainder of overload resolution.
3149
 
3150
+ [^2]: Note that cv-qualifiers on the type of objects are significant in
3151
  overload resolution for both glvalue and class prvalue objects.
3152
 
3153
+ [^3]: An implied object argument is contrived to correspond to the
3154
  implicit object parameter attributed to member functions during
3155
  overload resolution. It is not used in the call to the selected
3156
  function. Since the member functions all have the same implicit
3157
  object parameter, the contrived object will not be the cause to
3158
  select or reject a function.
3159
 
3160
+ [^4]: Note that this construction can yield candidate call functions
3161
  that cannot be differentiated one from the other by overload
3162
  resolution because they have identical declarations or differ only
3163
  in their return type. The call will be ambiguous if overload
3164
  resolution cannot select a match to the call that is uniquely better
3165
  than such undifferentiable functions.
3166
 
3167
+ [^5]: If the set of candidate functions is empty, overload resolution is
3168
  unsuccessful.
3169
 
3170
+ [^6]: If the value returned by the `operator->` function has class type,
3171
+ this can result in selecting and calling another `operator->`
3172
  function. The process repeats until an `operator->` function returns
3173
  a value of non-class type.
3174
 
3175
+ [^7]: The algorithm for selecting the best viable function is linear in
 
 
 
 
 
3176
  the number of viable functions. Run a simple tournament to find a
3177
  function `W` that is not worse than any opponent it faced. Although
3178
+ it is possible that another function `F` that `W` did not face is at
3179
+ least as good as `W`, `F` cannot be the best function because at
3180
+ some point in the tournament `F` encountered another function `G`
3181
+ such that `F` was not better than `G`. Hence, either `W` is the best
3182
+ function or there is no best function. So, make a second pass over
3183
+ the viable functions to verify that `W` is better than all other
3184
+ functions.
3185
 
3186
+ [^8]: Since there are no parameters of array type, this will only occur
3187
  as the referenced type of a reference parameter.
3188
 
3189
+ [^9]: Calling `operator++` explicitly, as in expressions like
3190
  `a.operator++(2)`, has no special properties: The argument to
3191
  `operator++` is `2`.