From Jason Turner

[over]

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

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpzo45s9jg/{from.md → to.md} +1222 -688
tmp/tmpzo45s9jg/{from.md → to.md} RENAMED
@@ -1,20 +1,21 @@
1
  # Overloading <a id="over">[[over]]</a>
2
 
 
 
3
  When two or more different declarations are specified for a single name
4
- in the same scope, that name is said to be *overloaded*. By extension,
5
- two declarations in the same scope that declare the same name but with
6
- different types are called *overloaded declarations*. Only function and
7
  function template declarations can be overloaded; variable and type
8
  declarations cannot be overloaded.
9
 
10
- When an overloaded function name is used in a call, which overloaded
11
- function declaration is being referenced is determined by comparing the
12
- types of the arguments at the point of use with the types of the
13
- parameters in the overloaded declarations that are visible at the point
14
- of use. This function selection process is called *overload resolution*
15
- and is defined in  [[over.match]].
16
 
17
  [*Example 1*:
18
 
19
  ``` cpp
20
  double abs(double);
@@ -32,78 +33,80 @@ Not all function declarations can be overloaded. Those that cannot be
32
  overloaded are specified here. A program is ill-formed if it contains
33
  two such non-overloadable declarations in the same scope.
34
 
35
  [*Note 1*: This restriction applies to explicit declarations in a
36
  scope, and between such declarations and declarations made through a
37
- *using-declaration* ([[namespace.udecl]]). It does not apply to sets of
38
  functions fabricated as a result of name lookup (e.g., because of
39
  *using-directive*s) or overload resolution (e.g., for operator
40
  functions). — *end note*]
41
 
42
  Certain function declarations cannot be overloaded:
43
 
44
  - Function declarations that differ only in the return type, the
45
- exception specification ([[except.spec]]), or both cannot be
46
- overloaded.
47
- - Member function declarations with the same name and the same
48
- parameter-type-list ([[dcl.fct]]) cannot be overloaded if any of them
49
- is a `static` member function declaration ([[class.static]]).
50
- Likewise, member function template declarations with the same name,
51
- the same parameter-type-list, and the same template parameter lists
52
- cannot be overloaded if any of them is a `static` member function
53
- template declaration. The types of the implicit object parameters
54
- constructed for the member functions for the purpose of overload
55
- resolution ([[over.match.funcs]]) are not considered when comparing
56
- parameter-type-lists for enforcement of this rule. In contrast, if
57
- there is no `static` member function declaration among a set of member
58
- function declarations with the same name and the same
59
- parameter-type-list, then these member function declarations can be
60
- overloaded if they differ in the type of their implicit object
61
- parameter.
62
  \[*Example 1*:
63
  The following illustrates this distinction:
64
  ``` cpp
65
  class X {
66
  static void f();
67
- void f(); // ill-formed
68
- void f() const; // ill-formed
69
- void f() const volatile; // ill-formed
70
  void g();
71
  void g() const; // OK: no static g
72
  void g() const volatile; // OK: no static g
73
  };
74
  ```
75
 
76
  — *end example*]
77
- - Member function declarations with the same name and the same
78
- parameter-type-list ([[dcl.fct]]) as well as member function template
79
- declarations with the same name, the same parameter-type-list, and the
80
- same template parameter lists cannot be overloaded if any of them, but
81
- not all, have a *ref-qualifier* ([[dcl.fct]]).
 
 
82
  \[*Example 2*:
83
  ``` cpp
84
  class Y {
85
  void h() &;
86
  void h() const &; // OK
87
  void h() &&; // OK, all declarations have a ref-qualifier
88
  void i() &;
89
- void i() const; // ill-formed, prior declaration of i
90
- // has a ref-qualifier
91
  };
92
  ```
93
 
94
  — *end example*]
95
 
96
  [*Note 2*:
97
 
98
  As specified in  [[dcl.fct]], function declarations that have equivalent
99
- parameter declarations declare the same function and therefore cannot be
 
100
  overloaded:
101
 
102
  - Parameter declarations that differ only in the use of equivalent
103
  typedef “types” are equivalent. A `typedef` is not a separate type,
104
- but only a synonym for another type ([[dcl.typedef]]).
105
  \[*Example 3*:
106
  ``` cpp
107
  typedef int Int;
108
 
109
  void f(int i);
@@ -124,13 +127,13 @@ overloaded:
124
  ```
125
 
126
  — *end example*]
127
  - Parameter declarations that differ only in a pointer `*` versus an
128
  array `[]` are equivalent. That is, the array declaration is adjusted
129
- to become a pointer declaration ([[dcl.fct]]). Only the second and
130
- subsequent array dimensions are significant in parameter types (
131
- [[dcl.array]]).
132
  \[*Example 5*:
133
  ``` cpp
134
  int f(char*);
135
  int f(char[]); // same as f(char*);
136
  int f(char[7]); // same as f(char*);
@@ -144,17 +147,17 @@ overloaded:
144
 
145
  — *end example*]
146
  - Parameter declarations that differ only in that one is a function type
147
  and the other is a pointer to the same function type are equivalent.
148
  That is, the function type is adjusted to become a pointer to function
149
- type ([[dcl.fct]]).
150
  \[*Example 6*:
151
  ``` cpp
152
  void h(int());
153
  void h(int (*)()); // redeclaration of h(int())
154
  void h(int x()) { } // definition of h(int())
155
- void h(int (*x)()) { } // ill-formed: redefinition of h(int())
156
  ```
157
 
158
  — *end example*]
159
  - Parameter declarations that differ only in the presence or absence of
160
  `const` and/or `volatile` are equivalent. That is, the `const` and
@@ -190,27 +193,49 @@ overloaded:
190
  void f (); // OK: overloaded declaration of f
191
 
192
  void prog () {
193
  f (1, 2); // OK: call f(int, int)
194
  f (1); // OK: call f(int, int)
195
- f (); // Error: f(int, int) or f()?
196
  }
197
  ```
198
 
199
  — *end example*]
200
 
201
  — *end note*]
202
 
203
  ## Declaration matching <a id="over.dcl">[[over.dcl]]</a>
204
 
205
  Two function declarations of the same name refer to the same function if
206
- they are in the same scope and have equivalent parameter declarations (
207
- [[over.load]]). A function member of a derived class is *not* in the
208
- same scope as a function member of the same name in a base class.
 
 
 
 
 
209
 
210
  [*Example 1*:
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  ``` cpp
213
  struct B {
214
  int f(int);
215
  };
216
 
@@ -233,11 +258,11 @@ void h(D* pd) {
233
  — *end example*]
234
 
235
  A locally declared function is not in the same scope as a function in a
236
  containing scope.
237
 
238
- [*Example 2*:
239
 
240
  ``` cpp
241
  void f(const char*);
242
  void g() {
243
  extern void f(int);
@@ -257,11 +282,11 @@ void caller () {
257
  — *end example*]
258
 
259
  Different versions of an overloaded member function can be given
260
  different access rules.
261
 
262
- [*Example 3*:
263
 
264
  ``` cpp
265
  class buffer {
266
  private:
267
  char* p;
@@ -292,73 +317,73 @@ as the accessibility of the function, can make its use in the calling
292
  context ill-formed. — *end note*]
293
 
294
  Overload resolution selects the function to call in seven distinct
295
  contexts within the language:
296
 
297
- - invocation of a function named in the function call syntax (
298
- [[over.call.func]]);
299
  - invocation of a function call operator, a pointer-to-function
300
  conversion function, a reference-to-pointer-to-function conversion
301
  function, or a reference-to-function conversion function on a class
302
- object named in the function call syntax ([[over.call.object]]);
303
- - invocation of the operator referenced in an expression (
304
- [[over.match.oper]]);
305
- - invocation of a constructor for default- or direct-initialization (
306
- [[dcl.init]]) of a class object ([[over.match.ctor]]);
307
- - invocation of a user-defined conversion for copy-initialization (
308
- [[dcl.init]]) of a class object ([[over.match.copy]]);
309
  - invocation of a conversion function for initialization of an object of
310
- a non-class type from an expression of class type (
311
- [[over.match.conv]]); and
312
- - invocation of a conversion function for conversion to a glvalue or
313
- class prvalue to which a reference ([[dcl.init.ref]]) will be
314
- directly bound ([[over.match.ref]]).
315
 
316
  Each of these contexts defines the set of candidate functions and the
317
  list of arguments in its own unique way. But, once the candidate
318
  functions and argument lists have been identified, the selection of the
319
  best function is the same in all cases:
320
 
321
  - First, a subset of the candidate functions (those that have the proper
322
  number of arguments and meet certain other conditions) is selected to
323
- form a set of viable functions ([[over.match.viable]]).
324
  - Then the best viable function is selected based on the implicit
325
- conversion sequences ([[over.best.ics]]) needed to match each
326
- argument to the corresponding parameter of each viable function.
327
 
328
  If a best viable function exists and is unique, overload resolution
329
  succeeds and produces it as the result. Otherwise overload resolution
330
  fails and the invocation is ill-formed. When overload resolution
331
- succeeds, and the best viable function is not accessible (Clause 
332
- [[class.access]]) in the context in which it is used, the program is
333
  ill-formed.
334
 
 
 
 
 
 
335
  ### Candidate functions and argument lists <a id="over.match.funcs">[[over.match.funcs]]</a>
336
 
337
  The subclauses of  [[over.match.funcs]] describe the set of candidate
338
  functions and the argument list submitted to overload resolution in each
339
- of the seven contexts in which overload resolution is used. The source
340
- transformations and constructions defined in these subclauses are only
341
- for the purpose of describing the overload resolution process. An
342
- implementation is not required to use such transformations and
343
- constructions.
344
 
345
  The set of candidate functions can contain both member and non-member
346
  functions to be resolved against the same argument list. So that
347
  argument and parameter lists are comparable within this heterogeneous
348
- set, a member function is considered to have an extra parameter, called
349
- the *implicit object parameter*, which represents the object for which
350
- the member function has been called. For the purposes of overload
351
  resolution, both static and non-static member functions have an implicit
352
  object parameter, but constructors do not.
353
 
354
  Similarly, when appropriate, the context can construct an argument list
355
- that contains an *implied object argument* to denote the object to be
356
- operated on. Since arguments and parameters are associated by position
357
- within their respective lists, the convention is that the implicit
358
- object parameter, if present, is always the first parameter and the
359
- implied object argument, if present, is always the first argument.
360
 
361
  For non-static member functions, the type of the implicit object
362
  parameter is
363
 
364
  - “lvalue reference to cv `X`” for functions declared without a
@@ -382,25 +407,25 @@ defining the type of the implicit object parameter. For static member
382
  functions, the implicit object parameter is considered to match any
383
  object (since if the function is selected, the object is discarded).
384
 
385
  [*Note 1*: No actual type is established for the implicit object
386
  parameter of a static member function, and no attempt will be made to
387
- determine a conversion sequence for that parameter (
388
- [[over.match.best]]). — *end note*]
389
 
390
  During overload resolution, the implied object argument is
391
  indistinguishable from other arguments. The implicit object parameter,
392
  however, retains its identity since no user-defined conversions can be
393
  applied to achieve a type match with it. For non-static member functions
394
- declared without a *ref-qualifier*, an additional rule applies:
 
 
 
395
 
396
- - even if the implicit object parameter is not const-qualified, an
397
- rvalue can be bound to the parameter as long as in all other respects
398
- the argument can be converted to the type of the implicit object
399
- parameter. \[*Note 2*: The fact that such an argument is an rvalue
400
- does not affect the ranking of implicit conversion sequences (
401
- [[over.ics.rank]]). — *end note*]
402
 
403
  Because other than in list-initialization only one user-defined
404
  conversion is allowed in an implicit conversion sequence, special rules
405
  apply when selecting the best user-defined conversion (
406
  [[over.match.best]], [[over.best.ics]]).
@@ -415,46 +440,80 @@ public:
415
 
416
  class C : T {
417
  public:
418
  C(int);
419
  };
420
- T a = 1; // ill-formed: T(C(1)) not tried
421
  ```
422
 
423
  — *end example*]
424
 
425
  In each case where a candidate is a function template, candidate
426
  function template specializations are generated using template argument
427
- deduction ([[temp.over]], [[temp.deduct]]). Those candidates are then
428
- handled as candidate functions in the usual way.[^2] A given name can
429
- refer to one or more function templates and also to a set of overloaded
430
- non-template functions. In such a case, the candidate functions
431
- generated from each function template are combined with the set of
432
- non-template candidate functions.
433
-
434
- A defaulted move constructor or assignment operator ([[class.copy]])
435
- that is defined as deleted is excluded from the set of candidate
436
- functions in all contexts.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
437
 
438
  #### Function call syntax <a id="over.match.call">[[over.match.call]]</a>
439
 
440
- In a function call ([[expr.call]])
441
 
442
  ``` bnf
443
  postfix-expression '(' expression-listₒₚₜ ')'
444
  ```
445
 
446
- if the *postfix-expression* denotes a set of overloaded functions and/or
447
- function templates, overload resolution is applied as specified in
448
  [[over.call.func]]. If the *postfix-expression* denotes an object of
449
  class type, overload resolution is applied as specified in
450
  [[over.call.object]].
451
 
452
- If the *postfix-expression* denotes the address of a set of overloaded
453
- functions and/or function templates, overload resolution is applied
454
- using that set as described above. If the function selected by overload
455
- resolution is a non-static member function, the program is ill-formed.
456
 
457
  [*Note 1*: The resolution of the address of an overload set in other
458
  contexts is described in [[over.over]]. — *end note*]
459
 
460
  ##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
@@ -476,82 +535,75 @@ These represent two syntactic subcategories of function calls: qualified
476
  function calls and unqualified function calls.
477
 
478
  In qualified function calls, the name to be resolved is an
479
  *id-expression* and is preceded by an `->` or `.` operator. Since the
480
  construct `A->B` is generally equivalent to `(*A).B`, the rest of
481
- Clause  [[over]] assumes, without loss of generality, that all member
482
- function calls have been normalized to the form that uses an object and
483
- the `.` operator. Furthermore, Clause  [[over]] assumes that the
484
- *postfix-expression* that is the left operand of the `.` operator has
485
- type “cv `T`” where `T` denotes a class[^3]. Under this assumption, the
486
- *id-expression* in the call is looked up as a member function of `T`
487
- following the rules for looking up names in classes (
488
- [[class.member.lookup]]). The function declarations found by that lookup
489
- constitute the set of candidate functions. The argument list is the
490
- *expression-list* in the call augmented by the addition of the left
491
- operand of the `.` operator in the normalized member function call as
492
- the implied object argument ([[over.match.funcs]]).
493
 
494
  In unqualified function calls, the name is not qualified by an `->` or
495
  `.` operator and has the more general form of a *primary-expression*.
496
  The name is looked up in the context of the function call following the
497
- normal rules for name lookup in function calls ([[basic.lookup]]). The
498
  function declarations found by that lookup constitute the set of
499
  candidate functions. Because of the rules for name lookup, the set of
500
  candidate functions consists (1) entirely of non-member functions or (2)
501
  entirely of member functions of some class `T`. In case (1), the
502
  argument list is the same as the *expression-list* in the call. In case
503
  (2), the argument list is the *expression-list* in the call augmented by
504
  the addition of an implied object argument as in a qualified function
505
- call. If the keyword `this` ([[class.this]]) is in scope and refers to
506
  class `T`, or a derived class of `T`, then the implied object argument
507
  is `(*this)`. If the keyword `this` is not in scope or refers to another
508
  class, then a contrived object of type `T` becomes the implied object
509
- argument[^4]. If the argument list is augmented by a contrived object
510
  and overload resolution selects one of the non-static member functions
511
  of `T`, the call is ill-formed.
512
 
513
  ##### Call to object of class type <a id="over.call.object">[[over.call.object]]</a>
514
 
515
- If the *primary-expression* `E` in the function call syntax evaluates to
516
  a class object of type “cv `T`”, then the set of candidate functions
517
  includes at least the function call operators of `T`. The function call
518
  operators of `T` are obtained by ordinary lookup of the name
519
  `operator()` in the context of `(E).operator()`.
520
 
521
  In addition, for each non-explicit conversion function declared in `T`
522
  of the form
523
 
524
  ``` bnf
525
- 'operator' conversion-type-id '( )' cv-qualifier ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ ';'
526
  ```
527
 
528
- where *cv-qualifier* is the same cv-qualification as, or a greater
529
- cv-qualification than, cv, and where *conversion-type-id* denotes the
530
- type “pointer to function of (`P₁`, …, `Pₙ`) returning `R`”, or the type
531
- “reference to pointer to function of (`P₁`, …, `Pₙ`) returning `R`”, or
532
- the type “reference to function of (`P₁`, …, `Pₙ`) returning `R`”, a
533
- *surrogate call function* with the unique name *call-function* and
534
- having the form
535
 
536
  ``` bnf
537
- 'R' call-function '(' conversion-type-id \ %
538
  'F, P₁ a₁, …, Pₙ aₙ)' '{ return F (a₁, …, aₙ); }'
539
  ```
540
 
541
  is also considered as a candidate function. Similarly, surrogate call
542
  functions are added to the set of candidate functions for each
543
  non-explicit conversion function declared in a base class of `T`
544
  provided the function is not hidden within `T` by another intervening
545
- declaration[^5].
546
-
547
- If such a surrogate call function is selected by overload resolution,
548
- the corresponding conversion function will be called to convert `E` to
549
- the appropriate function pointer or reference, and the function will
550
- then be invoked with the arguments of the call. If the conversion
551
- function cannot be called (e.g., because of an ambiguity), the program
552
- is ill-formed.
553
 
554
  The argument list submitted to overload resolution consists of the
555
  argument expressions present in the function call syntax preceded by the
556
  implied object argument `(E)`.
557
 
@@ -583,18 +635,18 @@ int i = a(1); // calls f1 via pointer returned from conversion
583
 
584
  #### Operators in expressions <a id="over.match.oper">[[over.match.oper]]</a>
585
 
586
  If no operand of an operator in an expression has a type that is a class
587
  or an enumeration, the operator is assumed to be a built-in operator and
588
- interpreted according to Clause  [[expr]].
589
 
590
  [*Note 1*: Because `.`, `.*`, and `::` cannot be overloaded, these
591
- operators are always built-in operators interpreted according to Clause 
592
- [[expr]]. `?:` cannot be overloaded, but the rules in this subclause are
593
- used to determine the conversions to be applied to the second and third
594
- operands when they have class or enumeration type (
595
- [[expr.cond]]). — *end note*]
596
 
597
  [*Example 1*:
598
 
599
  ``` cpp
600
  struct String {
@@ -603,11 +655,12 @@ struct String {
603
  operator const char* ();
604
  };
605
  String operator + (const String&, const String&);
606
 
607
  void f() {
608
- const char* p= "one" + "two"; // ill-formed because neither operand has class or enumeration type
 
609
  int I = 1 + 1; // always evaluates to 2 even if class or enumeration types exist
610
  // that would perform the operation.
611
  }
612
  ```
613
 
@@ -618,16 +671,16 @@ user-defined operator function might be declared that implements this
618
  operator or a user-defined conversion can be necessary to convert the
619
  operand to a type that is appropriate for a built-in operator. In this
620
  case, overload resolution is used to determine which operator function
621
  or built-in operator is to be invoked to implement the operator.
622
  Therefore, the operator notation is first transformed to the equivalent
623
- function-call notation as summarized in Table  [[tab:over.rel.op.func]]
624
- (where `@` denotes one of the operators covered in the specified
625
- subclause). However, the operands are sequenced in the order prescribed
626
- for the built-in operator (Clause  [[expr]]).
627
 
628
- **Table: Relationship between operator and function call notation** <a id="tab:over.rel.op.func">[tab:over.rel.op.func]</a>
629
 
630
  | Subclause | Expression | As member function | As non-member function |
631
  | ------------ | ---------- | ------------------- | ---------------------- |
632
  | (a)} |
633
  | (a, b)} |
@@ -635,25 +688,24 @@ for the built-in operator (Clause  [[expr]]).
635
  | [[over.sub]] | `a[b]` | `(a).operator[](b)` | |
636
  | [[over.ref]] | `a->` | `(a).operator->( )` | |
637
  | (a, 0)} |
638
 
639
 
640
- For a unary operator `@` with an operand of a type whose cv-unqualified
641
- version is `T1`, and for a binary operator `@` with a left operand of a
642
- type whose cv-unqualified version is `T1` and a right operand of a type
643
- whose cv-unqualified version is `T2`, three sets of candidate functions,
644
- designated *member candidates*, *non-member candidates* and *built-in
645
- candidates*, are constructed as follows:
646
 
647
  - If `T1` is a complete class type or a class currently being defined,
648
  the set of member candidates is the result of the qualified lookup of
649
- `T1::operator@` ([[over.call.func]]); otherwise, the set of member
650
  candidates is empty.
651
  - The set of non-member candidates is the result of the unqualified
652
  lookup of `operator@` in the context of the expression according to
653
- the usual rules for name lookup in unqualified function calls (
654
- [[basic.lookup.argdep]]) except that all member functions are ignored.
655
  However, if no operand has a class type, only those non-member
656
  functions in the lookup set that have a first parameter of type `T1`
657
  or “reference to cv `T1`”, when `T1` is an enumeration type, or (if
658
  there is a right operand) a second parameter of type `T2` or
659
  “reference to cv `T2`”, when `T2` is an enumeration type, are
@@ -666,26 +718,48 @@ candidates*, are constructed as follows:
666
  - accept the same number of operands, and
667
  - accept operand types to which the given operand or operands can be
668
  converted according to [[over.best.ics]], and
669
  - do not have the same parameter-type-list as any non-member candidate
670
  that is not a function template specialization.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
671
 
672
  For the built-in assignment operators, conversions of the left operand
673
  are restricted as follows:
674
 
675
  - no temporaries are introduced to hold the left operand, and
676
  - no user-defined conversions are applied to the left operand to achieve
677
  a type match with the left-most parameter of a built-in candidate.
678
 
679
  For all other operators, no such restrictions apply.
680
 
681
- The set of candidate functions for overload resolution is the union of
682
- the member candidates, the non-member candidates, and the built-in
683
- candidates. The argument list contains all of the operands of the
684
- operator. The best function from the set of candidate functions is
685
- selected according to  [[over.match.viable]] and 
686
- [[over.match.best]].[^6]
 
 
687
 
688
  [*Example 2*:
689
 
690
  ``` cpp
691
  struct A {
@@ -698,17 +772,36 @@ void m() {
698
  }
699
  ```
700
 
701
  — *end example*]
702
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
703
  If a built-in candidate is selected by overload resolution, the operands
704
  of class type are converted to the types of the corresponding parameters
705
  of the selected operation function, except that the second standard
706
- conversion sequence of a user-defined conversion sequence (
707
- [[over.ics.user]]) is not applied. Then the operator is treated as the
708
- corresponding built-in operator and interpreted according to Clause 
709
- [[expr]].
710
 
711
  [*Example 3*:
712
 
713
  ``` cpp
714
  struct X {
@@ -730,14 +823,14 @@ The second operand of operator `->` is ignored in selecting an
730
  function is called. When `operator->` returns, the operator `->` is
731
  applied to the value returned, with the original second operand.[^7]
732
 
733
  If the operator is the operator `,`, the unary operator `&`, or the
734
  operator `->`, and there are no viable functions, then the operator is
735
- assumed to be the built-in operator and interpreted according to Clause 
736
- [[expr]].
737
 
738
- [*Note 2*:
739
 
740
  The lookup rules for operators in expressions are different than the
741
  lookup rules for operator function names in a function call, as shown in
742
  the following example:
743
 
@@ -760,19 +853,20 @@ void B::f() {
760
 
761
  — *end note*]
762
 
763
  #### Initialization by constructor <a id="over.match.ctor">[[over.match.ctor]]</a>
764
 
765
- When objects of class type are direct-initialized ([[dcl.init]]),
766
- copy-initialized from an expression of the same or a derived class
767
- type ([[dcl.init]]), or default-initialized ([[dcl.init]]), overload
768
- resolution selects the constructor. For direct-initialization or
769
  default-initialization that is not in the context of
770
  copy-initialization, the candidate functions are all the constructors of
771
- the class of the object being initialized. For copy-initialization, the
772
- candidate functions are all the converting constructors (
773
- [[class.conv.ctor]]) of that class. The argument list is the
 
774
  *expression-list* or *assignment-expression* of the *initializer*.
775
 
776
  #### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
777
 
778
  Under the conditions specified in  [[dcl.init]], as part of a
@@ -786,25 +880,25 @@ to a possibly cv-qualified class type is determined in terms of a
786
  corresponding non-reference copy-initialization. — *end note*]
787
 
788
  Assuming that “*cv1* `T`” is the type of the object being initialized,
789
  with `T` a class type, the candidate functions are selected as follows:
790
 
791
- - The converting constructors ([[class.conv.ctor]]) of `T` are
792
- candidate functions.
793
  - When the type of the initializer expression is a class type “cv `S`”,
794
  the non-explicit conversion functions of `S` and its base classes are
795
- considered. When initializing a temporary to be bound to the first
796
- parameter of a constructor where the parameter is of type “reference
797
- to possibly cv-qualified `T`” and the constructor is called with a
798
  single argument in the context of direct-initialization of an object
799
- of type “*cv2* `T`”, explicit conversion functions are also
800
  considered. Those that are not hidden within `S` and yield a type
801
  whose cv-unqualified version is the same type as `T` or is a derived
802
- class thereof are candidate functions. Conversion functions that
803
- return “reference to `X`” return lvalues or xvalues, depending on the
804
- type of reference, of type `X` and are therefore considered to yield
805
- `X` for this process of selecting candidate functions.
806
 
807
  In both cases, the argument list has one argument, which is the
808
  initializer expression.
809
 
810
  [*Note 2*: This argument will be compared against the first parameter
@@ -823,120 +917,226 @@ the initializer expression, with `S` a class type, the candidate
823
  functions are selected as follows:
824
 
825
  - The conversion functions of `S` and its base classes are considered.
826
  Those non-explicit conversion functions that are not hidden within `S`
827
  and yield type `T` or a type that can be converted to type `T` via a
828
- standard conversion sequence ([[over.ics.scs]]) are candidate
829
- functions. For direct-initialization, those explicit conversion
830
- functions that are not hidden within `S` and yield type `T` or a type
831
- that can be converted to type `T` with a qualification conversion (
832
- [[conv.qual]]) are also candidate functions. Conversion functions that
833
- return a cv-qualified type are considered to yield the cv-unqualified
834
- version of that type for this process of selecting candidate
835
- functions. Conversion functions that return “reference to *cv2* `X`”
836
- return lvalues or xvalues, depending on the type of reference, of type
837
- “*cv2* `X`” and are therefore considered to yield `X` for this process
838
- of selecting candidate functions.
839
 
840
  The argument list has one argument, which is the initializer expression.
841
 
842
  [*Note 1*: This argument will be compared against the implicit object
843
  parameter of the conversion functions. — *end note*]
844
 
845
  #### Initialization by conversion function for direct reference binding <a id="over.match.ref">[[over.match.ref]]</a>
846
 
847
  Under the conditions specified in  [[dcl.init.ref]], a reference can be
848
- bound directly to a glvalue or class prvalue that is the result of
849
- applying a conversion function to an initializer expression. Overload
850
- resolution is used to select the conversion function to be invoked.
851
- Assuming that “reference to *cv1* `T`” is the type of the reference
852
- being initialized, and “cv `S` is the type of the initializer
853
- expression, with `S` a class type, the candidate functions are selected
854
- as follows:
855
 
856
  - The conversion functions of `S` and its base classes are considered.
857
  Those non-explicit conversion functions that are not hidden within `S`
858
  and yield type “lvalue reference to *cv2* `T2`” (when initializing an
859
  lvalue reference or an rvalue reference to function) or “*cv2* `T2`”
860
  or “rvalue reference to *cv2* `T2`” (when initializing an rvalue
861
  reference or an lvalue reference to function), where “*cv1* `T`” is
862
- reference-compatible ([[dcl.init.ref]]) with “*cv2* `T2`”, are
863
- candidate functions. For direct-initialization, those explicit
864
- conversion functions that are not hidden within `S` and yield type
865
- “lvalue reference to *cv2* `T2`” or “*cv2* `T2`” or “rvalue reference
866
- to *cv2* `T2`”, respectively, where `T2` is the same type as `T` or
867
- can be converted to type `T` with a qualification conversion (
868
- [[conv.qual]]), are also candidate functions.
 
 
869
 
870
  The argument list has one argument, which is the initializer expression.
871
 
872
  [*Note 1*: This argument will be compared against the implicit object
873
  parameter of the conversion functions. — *end note*]
874
 
875
  #### Initialization by list-initialization <a id="over.match.list">[[over.match.list]]</a>
876
 
877
  When objects of non-aggregate class type `T` are list-initialized such
878
  that [[dcl.init.list]] specifies that overload resolution is performed
879
- according to the rules in this section, overload resolution selects the
880
- constructor in two phases:
 
881
 
882
- - Initially, the candidate functions are the initializer-list
883
- constructors ([[dcl.init.list]]) of the class `T` and the argument
884
- list consists of the initializer list as a single argument.
885
- - If no viable initializer-list constructor is found, overload
886
- resolution is performed again, where the candidate functions are all
887
- the constructors of the class `T` and the argument list consists of
888
- the elements of the initializer list.
 
 
889
 
890
- If the initializer list has no elements and `T` has a default
891
- constructor, the first phase is omitted. In copy-list-initialization, if
892
- an `explicit` constructor is chosen, the initialization is ill-formed.
893
 
894
- [*Note 1*: This differs from other situations ([[over.match.ctor]], 
895
  [[over.match.copy]]), where only converting constructors are considered
896
  for copy-initialization. This restriction only applies if this
897
  initialization is part of the final result of overload
898
  resolution. — *end note*]
899
 
900
  #### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
901
 
902
- A set of functions and function templates is formed comprising:
 
 
 
903
 
904
- - For each constructor of the primary class template designated by the
905
- *template-name*, if the template is defined, a function template with
906
- the following properties:
907
- - The template parameters are the template parameters of the class
908
- template followed by the template parameters (including default
909
- template arguments) of the constructor, if any.
910
  - The types of the function parameters are those of the constructor.
911
  - The return type is the class template specialization designated by
912
- the *template-name* and template arguments corresponding to the
913
- template parameters obtained from the class template.
914
- - If the primary class template `C` is not defined or does not declare
915
- any constructors, an additional function template derived as above
916
- from a hypothetical constructor `C()`.
917
  - An additional function template derived as above from a hypothetical
918
  constructor `C(C)`, called the *copy deduction candidate*.
919
  - For each *deduction-guide*, a function or function template with the
920
  following properties:
921
  - The template parameters, if any, and function parameters are those
922
  of the *deduction-guide*.
923
  - The return type is the *simple-template-id* of the
924
  *deduction-guide*.
925
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
926
  Initialization and overload resolution are performed as described in
927
  [[dcl.init]] and [[over.match.ctor]], [[over.match.copy]], or
928
  [[over.match.list]] (as appropriate for the type of initialization
929
- performed) for an object of a hypothetical class type, where the
930
- selected functions and function templates are considered to be the
931
  constructors of that class type for the purpose of forming an overload
932
  set, and the initializer is provided by the context in which class
933
- template argument deduction was performed. Each such notional
934
- constructor is considered to be explicit if the function or function
935
- template was generated from a constructor or *deduction-guide* that was
936
- declared `explicit`. All such notional constructors are considered to be
937
- public members of the hypothetical class type.
 
 
 
 
 
 
 
 
 
 
 
 
 
938
 
939
  [*Example 1*:
940
 
941
  ``` cpp
942
  template <class T> struct A {
@@ -964,44 +1164,163 @@ template <class T> struct B {
964
  template <class U> using TA = T;
965
  template <class U> B(U, TA<U>);
966
  };
967
 
968
  B b{(int*)0, (char*)0}; // OK, deduces B<char*>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
969
  ```
970
 
971
  — *end example*]
972
 
973
  ### Viable functions <a id="over.match.viable">[[over.match.viable]]</a>
974
 
975
- From the set of candidate functions constructed for a given context (
976
- [[over.match.funcs]]), a set of viable functions is chosen, from which
977
  the best function will be selected by comparing argument conversion
978
- sequences for the best fit ([[over.match.best]]). The selection of
979
- viable functions considers relationships between arguments and function
980
- parameters other than the ranking of conversion sequences.
 
981
 
982
  First, to be a viable function, a candidate function shall have enough
983
  parameters to agree in number with the arguments in the list.
984
 
985
  - If there are *m* arguments in the list, all candidate functions having
986
  exactly *m* parameters are viable.
987
  - A candidate function having fewer than *m* parameters is viable only
988
- if it has an ellipsis in its parameter list ([[dcl.fct]]). For the
989
  purposes of overload resolution, any argument for which there is no
990
- corresponding parameter is considered to “match the ellipsis” (
991
- [[over.ics.ellipsis]]) .
992
  - A candidate function having more than *m* parameters is viable only if
993
- the *(m+1)*-st parameter has a default argument (
994
- [[dcl.fct.default]]).[^8] For the purposes of overload resolution, the
995
  parameter list is truncated on the right, so that there are exactly
996
  *m* parameters.
997
 
998
- Second, for `F` to be a viable function, there shall exist for each
999
- argument an *implicit conversion sequence* ([[over.best.ics]]) that
1000
- converts that argument to the corresponding parameter of `F`. If the
1001
- parameter has reference type, the implicit conversion sequence includes
1002
- the operation of binding the reference, and the fact that an lvalue
 
 
 
 
1003
  reference to non-`const` cannot be bound to an rvalue and that an rvalue
1004
  reference cannot be bound to an lvalue can affect the viability of the
1005
  function (see  [[over.ics.ref]]).
1006
 
1007
  ### Best viable function <a id="over.match.best">[[over.match.best]]</a>
@@ -1009,11 +1328,11 @@ function (see  [[over.ics.ref]]).
1009
  Define ICS*i*(`F`) as follows:
1010
 
1011
  - If `F` is a static member function, ICS*1*(`F`) is defined such that
1012
  ICS*1*(`F`) is neither better nor worse than ICS*1*(`G`) for any
1013
  function `G`, and, symmetrically, ICS*1*(`G`) is neither better nor
1014
- worse than ICS*1*(`F`);[^9] otherwise,
1015
  - let ICS*i*(`F`) denote the implicit conversion sequence that converts
1016
  the *i*-th argument in the list to the type of the *i*-th parameter of
1017
  viable function `F`. [[over.best.ics]] defines the implicit conversion
1018
  sequences and [[over.ics.rank]] defines what it means for one implicit
1019
  conversion sequence to be a better conversion sequence or worse
@@ -1046,14 +1365,14 @@ and then
1046
  ```
1047
 
1048
  — *end example*]
1049
  or, if not that,
1050
  - the context is an initialization by conversion function for direct
1051
- reference binding ([[over.match.ref]]) of a reference to function
1052
- type, the return type of `F1` is the same kind of reference (i.e.
1053
- lvalue or rvalue) as the reference being initialized, and the return
1054
- type of `F2` is not
1055
  \[*Example 2*:
1056
  ``` cpp
1057
  template <class T> struct A {
1058
  operator T&(); // #1
1059
  operator T&&(); // #2
@@ -1070,17 +1389,67 @@ and then
1070
  template specialization, or, if not that,
1071
  - `F1` and `F2` are function template specializations, and the function
1072
  template for `F1` is more specialized than the template for `F2`
1073
  according to the partial ordering rules described in 
1074
  [[temp.func.order]], or, if not that,
1075
- - `F1` is generated from a *deduction-guide* (
1076
- [[over.match.class.deduct]]) and `F2` is not, or, if not that,
1077
- - `F1` is the copy deduction candidate ([[over.match.class.deduct]])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1078
  and `F2` is not, or, if not that,
 
 
1079
  - `F1` is generated from a non-template constructor and `F2` is
1080
  generated from a constructor template.
1081
- \[*Example 3*:
1082
  ``` cpp
1083
  template <class T> struct A {
1084
  using value_type = T;
1085
  A(value_type); // #1
1086
  A(const A&); // #2
@@ -1106,13 +1475,13 @@ and then
1106
 
1107
  — *end example*]
1108
 
1109
  If there is exactly one viable function that is a better function than
1110
  all other viable functions, then it is the one selected by overload
1111
- resolution; otherwise the call is ill-formed.[^10]
1112
 
1113
- [*Example 4*:
1114
 
1115
  ``` cpp
1116
  void Fcn(const int*, short);
1117
  void Fcn(int*, int);
1118
 
@@ -1137,11 +1506,11 @@ If the best viable function resolves to a function for which multiple
1137
  declarations were found, and if at least two of these declarations — or
1138
  the declarations they refer to in the case of *using-declaration*s —
1139
  specify a default argument that made the function viable, the program is
1140
  ill-formed.
1141
 
1142
- [*Example 5*:
1143
 
1144
  ``` cpp
1145
  namespace A {
1146
  extern "C" void f(int = 5);
1147
  }
@@ -1152,41 +1521,43 @@ namespace B {
1152
  using A::f;
1153
  using B::f;
1154
 
1155
  void use() {
1156
  f(3); // OK, default argument was not used for viability
1157
- f(); // Error: found default argument twice
1158
  }
1159
  ```
1160
 
1161
  — *end example*]
1162
 
1163
  #### Implicit conversion sequences <a id="over.best.ics">[[over.best.ics]]</a>
1164
 
1165
  An *implicit conversion sequence* is a sequence of conversions used to
1166
  convert an argument in a function call to the type of the corresponding
1167
  parameter of the function being called. The sequence of conversions is
1168
- an implicit conversion as defined in Clause  [[conv]], which means it is
1169
  governed by the rules for initialization of an object or reference by a
1170
  single expression ([[dcl.init]], [[dcl.init.ref]]).
1171
 
1172
  Implicit conversion sequences are concerned only with the type,
1173
  cv-qualification, and value category of the argument and how these are
1174
- converted to match the corresponding properties of the parameter. Other
1175
- properties, such as the lifetime, storage class, alignment,
1176
- accessibility of the argument, whether the argument is a bit-field, and
1177
- whether a function is deleted ([[dcl.fct.def.delete]]), are ignored.
1178
- So, although an implicit conversion sequence can be defined for a given
1179
- argument-parameter pair, the conversion from the argument to the
1180
- parameter might still be ill-formed in the final analysis.
 
 
1181
 
1182
  A well-formed implicit conversion sequence is one of the following
1183
  forms:
1184
 
1185
- - a *standard conversion sequence* ([[over.ics.scs]]),
1186
- - a *user-defined conversion sequence* ([[over.ics.user]]), or
1187
- - an *ellipsis conversion sequence* ([[over.ics.ellipsis]]).
1188
 
1189
  However, if the target is
1190
 
1191
  - the first parameter of a constructor or
1192
  - the implicit object parameter of a user-defined conversion function
@@ -1203,25 +1574,25 @@ by
1203
  is the first parameter of a constructor of class `X`, and the
1204
  conversion is to `X` or reference to cv `X`,
1205
 
1206
  user-defined conversion sequences are not considered.
1207
 
1208
- [*Note 1*: These rules prevent more than one user-defined conversion
1209
  from being applied during overload resolution, thereby avoiding infinite
1210
  recursion. — *end note*]
1211
 
1212
  [*Example 1*:
1213
 
1214
  ``` cpp
1215
  struct Y { Y(int); };
1216
  struct A { operator int(); };
1217
  Y y1 = A(); // error: A::operator int() is not a candidate
1218
 
1219
- struct X { };
1220
  struct B { operator X(); };
1221
  B b;
1222
- X x({b}); // error: B::operator X() is not a candidate
1223
  ```
1224
 
1225
  — *end example*]
1226
 
1227
  For the case where the parameter type is a reference, see 
@@ -1231,12 +1602,12 @@ When the parameter type is not a reference, the implicit conversion
1231
  sequence models a copy-initialization of the parameter from the argument
1232
  expression. The implicit conversion sequence is the one required to
1233
  convert the argument expression to a prvalue of the type of the
1234
  parameter.
1235
 
1236
- [*Note 2*: When the parameter has a class type, this is a conceptual
1237
- conversion defined for the purposes of Clause  [[over]]; the actual
1238
  initialization is defined in terms of constructors and is not a
1239
  conversion. — *end note*]
1240
 
1241
  Any difference in top-level cv-qualification is subsumed by the
1242
  initialization itself and does not constitute a conversion.
@@ -1248,39 +1619,39 @@ case is the identity sequence; it contains no “conversion” from
1248
 
1249
  When the parameter has a class type and the argument expression has the
1250
  same type, the implicit conversion sequence is an identity conversion.
1251
  When the parameter has a class type and the argument expression has a
1252
  derived class type, the implicit conversion sequence is a
1253
- derived-to-base Conversion from the derived class to the base class.
1254
 
1255
- [*Note 3*: There is no such standard conversion; this derived-to-base
1256
- Conversion exists only in the description of implicit conversion
1257
  sequences. — *end note*]
1258
 
1259
- A derived-to-base Conversion has Conversion rank ([[over.ics.scs]]).
1260
 
1261
  In all contexts, when converting to the implicit object parameter or
1262
  when converting to the left operand of an assignment operation only
1263
  standard conversion sequences are allowed.
1264
 
1265
  If no conversions are required to match an argument to a parameter type,
1266
  the implicit conversion sequence is the standard conversion sequence
1267
- consisting of the identity conversion ([[over.ics.scs]]).
1268
 
1269
  If no sequence of conversions can be found to convert an argument to a
1270
  parameter type, an implicit conversion sequence cannot be formed.
1271
 
1272
- If several different sequences of conversions exist that each convert
1273
- the argument to the parameter type, the implicit conversion sequence
1274
- associated with the parameter is defined to be the unique conversion
1275
- sequence designated the *ambiguous conversion sequence*. For the purpose
1276
- of ranking implicit conversion sequences as described in 
1277
  [[over.ics.rank]], the ambiguous conversion sequence is treated as a
1278
  user-defined conversion sequence that is indistinguishable from any
1279
  other user-defined conversion sequence.
1280
 
1281
- [*Note 4*:
1282
 
1283
  This rule prevents a function from becoming non-viable because of an
1284
  ambiguous conversion sequence for one of its parameters.
1285
 
1286
  [*Example 3*:
@@ -1291,11 +1662,11 @@ class A { A (B&);};
1291
  class B { operator A (); };
1292
  class C { C (B&); };
1293
  void f(A) { }
1294
  void f(C) { }
1295
  B b;
1296
- f(b); // ill-formed: ambiguous because there is a conversion b → C (via constructor)
1297
  // and an (ambiguous) conversion b → A (via constructor or conversion function)
1298
  void f(B) { }
1299
  f(b); // OK, unambiguous
1300
  ```
1301
 
@@ -1310,69 +1681,66 @@ conversion of one of the arguments in the call is ambiguous.
1310
  The three forms of implicit conversion sequences mentioned above are
1311
  defined in the following subclauses.
1312
 
1313
  ##### Standard conversion sequences <a id="over.ics.scs">[[over.ics.scs]]</a>
1314
 
1315
- Table  [[tab:over.conversions]] summarizes the conversions defined in
1316
- Clause  [[conv]] and partitions them into four disjoint categories:
1317
- Lvalue Transformation, Qualification Adjustment, Promotion, and
1318
- Conversion.
1319
 
1320
- [*Note 5*: These categories are orthogonal with respect to value
1321
  category, cv-qualification, and data representation: the Lvalue
1322
  Transformations do not change the cv-qualification or data
1323
  representation of the type; the Qualification Adjustments do not change
1324
  the value category or data representation of the type; and the
1325
  Promotions and Conversions do not change the value category or
1326
  cv-qualification of the type. — *end note*]
1327
 
1328
- [*Note 6*: As described in Clause  [[conv]], a standard conversion
1329
- sequence is either the Identity conversion by itself (that is, no
1330
- conversion) or consists of one to three conversions from the other four
1331
- categories. If there are two or more conversions in the sequence, the
1332
- conversions are applied in the canonical order: **Lvalue
1333
- Transformation**, **Promotion** or **Conversion**, **Qualification
1334
- Adjustment**. — *end note*]
1335
 
1336
- Each conversion in Table  [[tab:over.conversions]] also has an
1337
- associated rank (Exact Match, Promotion, or Conversion). These are used
1338
- to rank standard conversion sequences ([[over.ics.rank]]). The rank of
1339
- a conversion sequence is determined by considering the rank of each
1340
- conversion in the sequence and the rank of any reference binding (
1341
- [[over.ics.ref]]). If any of those has Conversion rank, the sequence has
1342
- Conversion rank; otherwise, if any of those has Promotion rank, the
1343
- sequence has Promotion rank; otherwise, the sequence has Exact Match
1344
- rank.
1345
 
1346
- **Table: Conversions** <a id="tab:over.conversions">[tab:over.conversions]</a>
1347
 
1348
  | Conversion | Category | Rank | Subclause |
1349
  | ----------------------- | -------- | ---- | ----------------- |
1350
  | No conversions required | Identity | | |
1351
  | Integral promotions | | | [[conv.prom]] |
1352
  | Integral conversions | | | [[conv.integral]] |
1353
 
1354
 
1355
  ##### User-defined conversion sequences <a id="over.ics.user">[[over.ics.user]]</a>
1356
 
1357
- A user-defined conversion sequence consists of an initial standard
1358
- conversion sequence followed by a user-defined conversion (
1359
- [[class.conv]]) followed by a second standard conversion sequence. If
1360
- the user-defined conversion is specified by a constructor (
1361
- [[class.conv.ctor]]), the initial standard conversion sequence converts
1362
- the source type to the type required by the argument of the constructor.
1363
- If the user-defined conversion is specified by a conversion function (
1364
- [[class.conv.fct]]), the initial standard conversion sequence converts
1365
- the source type to the implicit object parameter of the conversion
1366
- function.
1367
 
1368
  The second standard conversion sequence converts the result of the
1369
- user-defined conversion to the target type for the sequence. Since an
1370
- implicit conversion sequence is an initialization, the special rules for
1371
- initialization by user-defined conversion apply when selecting the best
1372
- user-defined conversion for a user-defined conversion sequence (see 
1373
- [[over.match.best]] and  [[over.best.ics]]).
 
1374
 
1375
  If the user-defined conversion is specified by a specialization of a
1376
  conversion function template, the second standard conversion sequence
1377
  shall have exact match rank.
1378
 
@@ -1388,15 +1756,15 @@ An ellipsis conversion sequence occurs when an argument in a function
1388
  call is matched with the ellipsis parameter specification of the
1389
  function called (see  [[expr.call]]).
1390
 
1391
  ##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
1392
 
1393
- When a parameter of reference type binds directly ([[dcl.init.ref]]) to
1394
- an argument expression, the implicit conversion sequence is the identity
1395
  conversion, unless the argument expression has a type that is a derived
1396
  class of the parameter type, in which case the implicit conversion
1397
- sequence is a derived-to-base Conversion ([[over.best.ics]]).
1398
 
1399
  [*Example 4*:
1400
 
1401
  ``` cpp
1402
  struct A {};
@@ -1408,73 +1776,108 @@ int i = f(b); // calls f(B&), an exact match, rather than f(A&), a convers
1408
 
1409
  — *end example*]
1410
 
1411
  If the parameter binds directly to the result of applying a conversion
1412
  function to the argument expression, the implicit conversion sequence is
1413
- a user-defined conversion sequence ([[over.ics.user]]), with the second
1414
  standard conversion sequence either an identity conversion or, if the
1415
  conversion function returns an entity of a type that is a derived class
1416
- of the parameter type, a derived-to-base Conversion.
1417
 
1418
  When a parameter of reference type is not bound directly to an argument
1419
  expression, the conversion sequence is the one required to convert the
1420
  argument expression to the referenced type according to 
1421
  [[over.best.ics]]. Conceptually, this conversion sequence corresponds to
1422
  copy-initializing a temporary of the referenced type with the argument
1423
  expression. Any difference in top-level cv-qualification is subsumed by
1424
  the initialization itself and does not constitute a conversion.
1425
 
1426
  Except for an implicit object parameter, for which see 
1427
- [[over.match.funcs]], a standard conversion sequence cannot be formed if
1428
- it requires binding an lvalue reference other than a reference to a
1429
  non-volatile `const` type to an rvalue or binding an rvalue reference to
1430
  an lvalue other than a function lvalue.
1431
 
1432
- [*Note 7*: This means, for example, that a candidate function cannot be
1433
  a viable function if it has a non-`const` lvalue reference parameter
1434
  (other than the implicit object parameter) and the corresponding
1435
  argument would require a temporary to be created to initialize the
1436
  lvalue reference (see  [[dcl.init.ref]]). — *end note*]
1437
 
1438
  Other restrictions on binding a reference to a particular argument that
1439
  are not based on the types of the reference and the argument do not
1440
- affect the formation of a standard conversion sequence, however.
1441
 
1442
  [*Example 5*: A function with an “lvalue reference to `int`” parameter
1443
  can be a viable candidate even if the corresponding argument is an `int`
1444
  bit-field. The formation of implicit conversion sequences treats the
1445
  `int` bit-field as an `int` lvalue and finds an exact match with the
1446
  parameter. If the function is selected by overload resolution, the call
1447
  will nonetheless be ill-formed because of the prohibition on binding a
1448
- non-`const` lvalue reference to a bit-field (
1449
- [[dcl.init.ref]]). — *end example*]
1450
 
1451
  ##### List-initialization sequence <a id="over.ics.list">[[over.ics.list]]</a>
1452
 
1453
- When an argument is an initializer list ([[dcl.init.list]]), it is not
1454
- an expression and special rules apply for converting it to a parameter
1455
  type.
1456
 
1457
- If the parameter type is an aggregate class `X` and the initializer list
1458
- has a single element of type cv `U`, where `U` is `X` or a class derived
1459
- from `X`, the implicit conversion sequence is the one required to
1460
- convert the element to the parameter type.
 
 
1461
 
1462
- Otherwise, if the parameter type is a character array [^11] and the
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1463
  initializer list has a single element that is an appropriately-typed
1464
- string literal ([[dcl.init.string]]), the implicit conversion sequence
1465
  is the identity conversion.
1466
 
1467
  Otherwise, if the parameter type is `std::initializer_list<X>` and all
1468
  the elements of the initializer list can be implicitly converted to `X`,
1469
  the implicit conversion sequence is the worst conversion necessary to
1470
  convert an element of the list to `X`, or if the initializer list has no
1471
  elements, the identity conversion. This conversion can be a user-defined
1472
  conversion even in the context of a call to an initializer-list
1473
  constructor.
1474
 
1475
- [*Example 6*:
1476
 
1477
  ``` cpp
1478
  void f(std::initializer_list<int>);
1479
  f( {} ); // OK: f(initializer_list<int>) identity conversion
1480
  f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
@@ -1496,15 +1899,16 @@ void h(const IA&);
1496
  h({ 1, 2, 3 }); // OK: identity conversion
1497
  ```
1498
 
1499
  — *end example*]
1500
 
1501
- Otherwise, if the parameter type is “array of `N` `X`”, if there exists
1502
- an implicit conversion sequence for each element of the array from the
1503
- corresponding element of the initializer list (or from `{}` if there is
1504
- no such element), the implicit conversion sequence is the worst such
1505
- implicit conversion sequence.
 
1506
 
1507
  Otherwise, if the parameter is a non-aggregate class `X` and overload
1508
  resolution per  [[over.match.list]] chooses a single best constructor
1509
  `C` of `X` to perform the initialization of an object of type `X` from
1510
  the argument initializer list:
@@ -1521,11 +1925,11 @@ If multiple constructors are viable but none is better than the others,
1521
  the implicit conversion sequence is the ambiguous conversion sequence.
1522
  User-defined conversions are allowed for conversion of the initializer
1523
  list elements to the constructor parameter types except as noted in 
1524
  [[over.best.ics]].
1525
 
1526
- [*Example 7*:
1527
 
1528
  ``` cpp
1529
  struct A {
1530
  A(std::initializer_list<int>);
1531
  };
@@ -1557,15 +1961,15 @@ i({ {1,2}, {"bar"} }); // OK: i(D(A(std::initializer_list<int>{1,2\), C(std::st
1557
 
1558
  — *end example*]
1559
 
1560
  Otherwise, if the parameter has an aggregate type which can be
1561
  initialized from the initializer list according to the rules for
1562
- aggregate initialization ([[dcl.init.aggr]]), the implicit conversion
1563
  sequence is a user-defined conversion sequence with the second standard
1564
  conversion sequence an identity conversion.
1565
 
1566
- [*Example 8*:
1567
 
1568
  ``` cpp
1569
  struct A {
1570
  int m1;
1571
  double m2;
@@ -1578,14 +1982,14 @@ f( {1.0} ); // error: narrowing
1578
 
1579
  — *end example*]
1580
 
1581
  Otherwise, if the parameter is a reference, see  [[over.ics.ref]].
1582
 
1583
- [*Note 8*: The rules in this section will apply for initializing the
1584
  underlying temporary for the reference. — *end note*]
1585
 
1586
- [*Example 9*:
1587
 
1588
  ``` cpp
1589
  struct A {
1590
  int m1;
1591
  double m2;
@@ -1604,21 +2008,21 @@ g({1}); // same conversion as int to double
1604
  Otherwise, if the parameter type is not a class:
1605
 
1606
  - if the initializer list has one element that is not itself an
1607
  initializer list, the implicit conversion sequence is the one required
1608
  to convert the element to the parameter type;
1609
- \[*Example 10*:
1610
  ``` cpp
1611
  void f(int);
1612
  f( {'a'} ); // OK: same conversion as char to int
1613
  f( {1.0} ); // error: narrowing
1614
  ```
1615
 
1616
  — *end example*]
1617
  - if the initializer list has no elements, the implicit conversion
1618
  sequence is the identity conversion.
1619
- \[*Example 11*:
1620
  ``` cpp
1621
  void f(int);
1622
  f( { } ); // OK: identity conversion
1623
  ```
1624
 
@@ -1638,26 +2042,28 @@ sequence S1 is neither better than nor worse than conversion sequence
1638
  S2, S1 and S2 are said to be *indistinguishable conversion sequences*.
1639
 
1640
  When comparing the basic forms of implicit conversion sequences (as
1641
  defined in  [[over.best.ics]])
1642
 
1643
- - a standard conversion sequence ([[over.ics.scs]]) is a better
1644
- conversion sequence than a user-defined conversion sequence or an
1645
- ellipsis conversion sequence, and
1646
- - a user-defined conversion sequence ([[over.ics.user]]) is a better
1647
- conversion sequence than an ellipsis conversion sequence (
1648
- [[over.ics.ellipsis]]).
1649
 
1650
  Two implicit conversion sequences of the same form are indistinguishable
1651
  conversion sequences unless one of the following rules applies:
1652
 
1653
  - List-initialization sequence `L1` is a better conversion sequence than
1654
  list-initialization sequence `L2` if
1655
  - `L1` converts to `std::initializer_list<X>` for some `X` and `L2`
1656
  does not, or, if not that,
1657
- - `L1` converts to type “array of `N1` `T`”, `L2` converts to type
1658
- “array of `N2` `T`”, and `N1` is smaller than `N2`,
 
 
1659
 
1660
  even if one of the other rules in this paragraph would otherwise
1661
  apply.
1662
  \[*Example 1*:
1663
  ``` cpp
@@ -1668,10 +2074,24 @@ conversion sequences unless one of the following rules applies:
1668
  void f2(std::pair<const char*, const char*>); // #3
1669
  void f2(std::initializer_list<std::string>); // #4
1670
  void g2() { f2({"foo","bar"}); } // chooses #4
1671
  ```
1672
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1673
  — *end example*]
1674
  - Standard conversion sequence `S1` is a better conversion sequence than
1675
  standard conversion sequence `S2` if
1676
  - `S1` is a proper subsequence of `S2` (comparing the conversion
1677
  sequences in the canonical form defined by  [[over.ics.scs]],
@@ -1679,15 +2099,15 @@ conversion sequences unless one of the following rules applies:
1679
  sequence is considered to be a subsequence of any non-identity
1680
  conversion sequence) or, if not that,
1681
  - the rank of `S1` is better than the rank of `S2`, or `S1` and `S2`
1682
  have the same rank and are distinguishable by the rules in the
1683
  paragraph below, or, if not that,
1684
- - `S1` and `S2` are reference bindings ([[dcl.init.ref]]) and neither
1685
- refers to an implicit object parameter of a non-static member
1686
- function declared without a *ref-qualifier*, and `S1` binds an
1687
- rvalue reference to an rvalue and `S2` binds an lvalue reference
1688
- \[*Example 2*:
1689
  ``` cpp
1690
  int i;
1691
  int f1();
1692
  int&& f2();
1693
  int g(const int&);
@@ -1711,45 +2131,43 @@ conversion sequences unless one of the following rules applies:
1711
  a.p(); // calls A::p()&
1712
  ```
1713
 
1714
  — *end example*]
1715
  or, if not that,
1716
- - `S1` and `S2` are reference bindings ([[dcl.init.ref]]) and `S1`
1717
  binds an lvalue reference to a function lvalue and `S2` binds an
1718
  rvalue reference to a function lvalue
1719
- \[*Example 3*:
1720
  ``` cpp
1721
  int f(void(&)()); // #1
1722
  int f(void(&&)()); // #2
1723
  void g();
1724
  int i1 = f(g); // calls #1
1725
  ```
1726
 
1727
  — *end example*]
1728
  or, if not that,
1729
- - `S1`
1730
- and `S2` differ only in their qualification conversion and yield
1731
- similar types `T1` and `T2` ([[conv.qual]]), respectively, and the
1732
- cv-qualification signature of type `T1` is a proper subset of the
1733
- cv-qualification signature of type `T2`
1734
- \[*Example 4*:
1735
  ``` cpp
1736
  int f(const volatile int *);
1737
  int f(const int *);
1738
  int i;
1739
  int j = f(&i); // calls f(const int*)
1740
  ```
1741
 
1742
  — *end example*]
1743
  or, if not that,
1744
  - `S1`
1745
- and `S2` are reference bindings ([[dcl.init.ref]]), and the types
1746
  to which the references refer are the same type except for top-level
1747
  cv-qualifiers, and the type to which the reference initialized by
1748
  `S2` refers is more cv-qualified than the type to which the
1749
  reference initialized by `S1` refers.
1750
- \[*Example 5*:
1751
  ``` cpp
1752
  int f(const int &);
1753
  int f(int &);
1754
  int g(const int &);
1755
  int g(int);
@@ -1773,11 +2191,11 @@ conversion sequences unless one of the following rules applies:
1773
  than another user-defined conversion sequence `U2` if they contain the
1774
  same user-defined conversion function or constructor or they
1775
  initialize the same class in an aggregate initialization and in either
1776
  case the second standard conversion sequence of `U1` is better than
1777
  the second standard conversion sequence of `U2`.
1778
- \[*Example 6*:
1779
  ``` cpp
1780
  struct A {
1781
  operator short();
1782
  } a;
1783
  int f(int);
@@ -1791,12 +2209,12 @@ conversion sequences unless one of the following rules applies:
1791
  Standard conversion sequences are ordered by their ranks: an Exact Match
1792
  is a better conversion than a Promotion, which is a better conversion
1793
  than a Conversion. Two conversion sequences with the same rank are
1794
  indistinguishable unless one of the following rules applies:
1795
 
1796
- - A conversion that does not convert a pointer, a pointer to member, or
1797
- `std::nullptr_t` to `bool` is better than one that does.
1798
  - A conversion that promotes an enumeration whose underlying type is
1799
  fixed to its underlying type is better than one that promotes to the
1800
  promoted underlying type, if the two are different.
1801
  - If class `B` is derived directly or indirectly from class `A`,
1802
  conversion of `B*` to `A*` is better than conversion of `B*` to
@@ -1804,11 +2222,11 @@ indistinguishable unless one of the following rules applies:
1804
  of `B*` to `void*`.
1805
  - If class `B` is derived directly or indirectly from class `A` and
1806
  class `C` is derived directly or indirectly from `B`,
1807
  - conversion of `C*` to `B*` is better than conversion of `C*` to
1808
  `A*`,
1809
- \[*Example 7*:
1810
  ``` cpp
1811
  struct A {};
1812
  struct B : public A {};
1813
  struct C : public B {};
1814
  C* pc;
@@ -1839,47 +2257,45 @@ indistinguishable unless one of the following rules applies:
1839
  [[over.match.best]]); in all other contexts, the source types will be
1840
  the same and the target types will be different. — *end note*]
1841
 
1842
  ## Address of overloaded function <a id="over.over">[[over.over]]</a>
1843
 
1844
- A use of an overloaded function name without arguments is resolved in
1845
- certain contexts to a function, a pointer to function or a pointer to
1846
- member function for a specific function from the overload set. A
1847
- function template name is considered to name a set of overloaded
1848
- functions in such contexts. A function with type `F` is selected for the
1849
- function type `FT` of the target type required in the context if `F`
1850
- (after possibly applying the function pointer conversion (
1851
- [[conv.fctptr]])) is identical to `FT`.
1852
-
1853
- [*Note 1*: That is, the class of which the function is a member is
1854
- ignored when matching a pointer-to-member-function type. — *end note*]
1855
-
1856
- The target can be
1857
 
1858
  - an object or reference being initialized ([[dcl.init]],
1859
  [[dcl.init.ref]], [[dcl.init.list]]),
1860
- - the left side of an assignment ([[expr.ass]]),
1861
- - a parameter of a function ([[expr.call]]),
1862
- - a parameter of a user-defined operator ([[over.oper]]),
1863
- - the return value of a function, operator function, or conversion (
1864
- [[stmt.return]]),
1865
  - an explicit type conversion ([[expr.type.conv]],
1866
  [[expr.static.cast]], [[expr.cast]]), or
1867
- - a non-type *template-parameter* ([[temp.arg.nontype]]).
1868
 
1869
- The overloaded function name can be preceded by the `&` operator. An
1870
- overloaded function name shall not be used without arguments in contexts
1871
- other than those listed.
1872
 
1873
- [*Note 2*: Any redundant set of parentheses surrounding the overloaded
1874
- function name is ignored ([[expr.prim]]). — *end note*]
1875
 
1876
- If the name is a function template, template argument deduction is
1877
- done ([[temp.deduct.funcaddr]]), and if the argument deduction
1878
- succeeds, the resulting template argument list is used to generate a
1879
- single function template specialization, which is added to the set of
1880
- overloaded functions considered.
 
 
 
 
 
 
 
 
1881
 
1882
  [*Note 3*: As described in  [[temp.arg.explicit]], if deduction fails
1883
  and the function template name is followed by an explicit template
1884
  argument list, the *template-id* is then examined to see whether it
1885
  identifies a single function template specialization. If it does, the
@@ -1887,23 +2303,28 @@ identifies a single function template specialization. If it does, the
1887
  specialization. The target type is not used in that
1888
  determination. — *end note*]
1889
 
1890
  Non-member functions and static member functions match targets of
1891
  function pointer type or reference to function type. Non-static member
1892
- functions match targets of pointer to member function type. If a
1893
  non-static member function is selected, the reference to the overloaded
1894
  function name is required to have the form of a pointer to member as
1895
  described in  [[expr.unary.op]].
1896
 
1897
- If more than one function is selected, any function template
 
 
1898
  specializations in the set are eliminated if the set also contains a
1899
- function that is not a function template specialization, and any given
1900
- function template specialization `F1` is eliminated if the set contains
1901
- a second function template specialization whose function template is
1902
- more specialized than the function template of `F1` according to the
1903
- partial ordering rules of  [[temp.func.order]]. After such eliminations,
1904
- if any, there shall remain exactly one selected function.
 
 
 
1905
 
1906
  [*Example 1*:
1907
 
1908
  ``` cpp
1909
  int f(double);
@@ -1967,38 +2388,53 @@ template*. A specialization of an operator function template is also an
1967
  operator function. An operator function is said to *implement* the
1968
  operator named in its *operator-function-id*.
1969
 
1970
  ``` bnf
1971
  operator-function-id:
1972
- 'operator' operator
1973
  ```
1974
 
1975
- [*Note 1*: The last two operators are function call ([[expr.call]])
1976
- and subscripting ([[expr.sub]]). The operators `new[]`, `delete[]`,
1977
- `()`, and `[]` are formed from more than one token. — *end note*]
 
 
 
 
 
 
 
 
 
 
1978
 
1979
  Both the unary and binary forms of
1980
 
1981
- ``` cpp
1982
- + - * &
1983
  ```
1984
 
1985
  can be overloaded.
1986
 
 
 
1987
  The following operators cannot be overloaded:
1988
 
1989
- ``` cpp
1990
- . .* :: ?:
1991
  ```
1992
 
1993
- nor can the preprocessing symbols `#` and `##` (Clause  [[cpp]]).
 
 
 
1994
 
1995
  Operator functions are usually not called directly; instead they are
1996
  invoked to evaluate the operators they implement ([[over.unary]] –
1997
  [[over.inc]]). They can be explicitly called, however, using the
1998
  *operator-function-id* as the name of the function in the function call
1999
- syntax ([[expr.call]]).
2000
 
2001
  [*Example 1*:
2002
 
2003
  ``` cpp
2004
  complex z = a.operator+(b); // complex z = a+b;
@@ -2006,83 +2442,133 @@ void* p = operator new(sizeof(int)*n);
2006
  ```
2007
 
2008
  — *end example*]
2009
 
2010
  The allocation and deallocation functions, `operator` `new`, `operator`
2011
- `new[]`, `operator` `delete` and `operator` `delete[]`, are described
2012
  completely in  [[basic.stc.dynamic]]. The attributes and restrictions
2013
  found in the rest of this subclause do not apply to them unless
2014
  explicitly stated in  [[basic.stc.dynamic]].
2015
 
 
 
 
 
2016
  An operator function shall either be a non-static member function or be
2017
  a non-member function that has at least one parameter whose type is a
2018
  class, a reference to a class, an enumeration, or a reference to an
2019
  enumeration. It is not possible to change the precedence, grouping, or
2020
  number of operands of operators. The meaning of the operators `=`,
2021
  (unary) `&`, and `,` (comma), predefined for each type, can be changed
2022
- for specific class and enumeration types by defining operator functions
2023
- that implement these operators. Operator functions are inherited in the
2024
- same manner as other base class functions.
 
 
2025
 
2026
- The identities among certain predefined operators applied to basic types
2027
- (for example, `++a` `a+=1`) need not hold for operator functions. Some
2028
- predefined operators, such as `+=`, require an operand to be an lvalue
2029
- when applied to basic types; this is not required by operator functions.
2030
 
2031
- An operator function cannot have default arguments (
2032
- [[dcl.fct.default]]), except where explicitly stated below. Operator
2033
- functions cannot have more or fewer parameters than the number required
2034
- for the corresponding operator, as described in the rest of this
2035
- subclause.
 
 
 
 
 
2036
 
2037
  Operators not mentioned explicitly in subclauses  [[over.ass]] through 
2038
  [[over.inc]] act as ordinary unary and binary operators obeying the
2039
  rules of  [[over.unary]] or  [[over.binary]].
2040
 
2041
  ### Unary operators <a id="over.unary">[[over.unary]]</a>
2042
 
2043
- A prefix unary operator shall be implemented by a non-static member
2044
- function ([[class.mfct]]) with no parameters or a non-member function
2045
- with one parameter. Thus, for any prefix unary operator `@`, `@x` can be
2046
- interpreted as either `x.operator@()` or `operator@(x)`. If both forms
2047
- of the operator function have been declared, the rules in 
2048
- [[over.match.oper]] determine which, if any, interpretation is used.
2049
- See  [[over.inc]] for an explanation of the postfix unary operators `++`
2050
- and `\dcr`.
 
 
 
 
 
 
 
 
 
 
 
 
 
2051
 
2052
  The unary and binary forms of the same operator are considered to have
2053
  the same name.
2054
 
2055
- [*Note 1*: Consequently, a unary operator can hide a binary operator
2056
  from an enclosing scope, and vice versa. — *end note*]
2057
 
2058
  ### Binary operators <a id="over.binary">[[over.binary]]</a>
2059
 
2060
- A binary operator shall be implemented either by a non-static member
2061
- function ([[class.mfct]]) with one parameter or by a non-member
2062
- function with two parameters. Thus, for any binary operator `@`, `x@y`
2063
- can be interpreted as either `x.operator@(y)` or `operator@(x,y)`. If
2064
- both forms of the operator function have been declared, the rules in 
2065
- [[over.match.oper]] determine which, if any, interpretation is used.
2066
-
2067
- ### Assignment <a id="over.ass">[[over.ass]]</a>
2068
-
2069
- An assignment operator shall be implemented by a non-static member
2070
- function with exactly one parameter. Because a copy assignment operator
2071
- `operator=` is implicitly declared for a class if not declared by the
2072
- user ([[class.copy]]), a base class assignment operator is always
2073
- hidden by the copy assignment operator of the derived class.
2074
-
2075
- Any assignment operator, even the copy and move assignment operators,
2076
- can be virtual.
2077
-
2078
- [*Note 1*:
2079
-
2080
- For a derived class `D` with a base class `B` for which a virtual
2081
- copy/move assignment has been declared, the copy/move assignment
2082
- operator in `D` does not override `B`’s virtual copy/move assignment
2083
- operator.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2084
 
2085
  [*Example 1*:
2086
 
2087
  ``` cpp
2088
  struct B {
@@ -2110,44 +2596,50 @@ void f() {
2110
 
2111
  — *end note*]
2112
 
2113
  ### Function call <a id="over.call">[[over.call]]</a>
2114
 
2115
- `operator()`
2116
-
2117
- shall be a non-static member function with an arbitrary number of
2118
- parameters. It can have default arguments. It implements the function
2119
- call syntax
2120
 
2121
  ``` bnf
2122
  postfix-expression '(' expression-listₒₚₜ ')'
2123
  ```
2124
 
2125
- where the *postfix-expression* evaluates to a class object and the
2126
- possibly empty *expression-list* matches the parameter list of an
2127
- `operator()` member function of the class. Thus, a call `x(arg1,...)` is
2128
- interpreted as `x.operator()(arg1, ...)` for a class object `x` of type
2129
- `T` if `T::operator()(T1,` `T2,` `T3)` exists and if the operator is
2130
- selected as the best match function by the overload resolution
2131
- mechanism ([[over.match.best]]).
 
 
 
 
 
 
 
2132
 
2133
  ### Subscripting <a id="over.sub">[[over.sub]]</a>
2134
 
2135
- `operator[]`
2136
-
2137
- shall be a non-static member function with exactly one parameter. It
2138
- implements the subscripting syntax
2139
 
2140
  ``` bnf
2141
  postfix-expression '[' expr-or-braced-init-list ']'
2142
  ```
2143
 
2144
- Thus, a subscripting expression `x[y]` is interpreted as
2145
- `x.operator[](y)` for a class object `x` of type `T` if
2146
- `T::operator[](T1)` exists and if the operator is selected as the best
2147
- match function by the overload resolution mechanism (
2148
- [[over.match.best]]).
 
 
2149
 
2150
  [*Example 1*:
2151
 
2152
  ``` cpp
2153
  struct X {
@@ -2161,37 +2653,36 @@ a[{1,2,3}] = 7; // error: built-in subscript operator
2161
 
2162
  — *end example*]
2163
 
2164
  ### Class member access <a id="over.ref">[[over.ref]]</a>
2165
 
2166
- `operator->`
2167
-
2168
- shall be a non-static member function taking no parameters. It
2169
- implements the class member access syntax that uses `->`.
2170
 
2171
  ``` bnf
2172
- postfix-expression '->' 'template'ₒₚₜ id-expression
2173
- postfix-expression '->' pseudo-destructor-name
2174
  ```
2175
 
2176
- An expression `x->m` is interpreted as `(x.operator->())->m` for a class
2177
- object `x` of type `T` if `T::operator->()` exists and if the operator
2178
- is selected as the best match function by the overload resolution
2179
- mechanism ([[over.match]]).
 
 
2180
 
2181
  ### Increment and decrement <a id="over.inc">[[over.inc]]</a>
2182
 
2183
- The user-defined function called `operator++` implements the prefix and
2184
- postfix `++` operator. If this function is a non-static member function
2185
- with no parameters, or a non-member function with one parameter, it
2186
- defines the prefix increment operator `++` for objects of that type. If
2187
- the function is a non-static member function with one parameter (which
2188
- shall be of type `int`) or a non-member function with two parameters
2189
- (the second of which shall be of type `int`), it defines the postfix
2190
- increment operator `++` for objects of that type. When the postfix
2191
- increment is called as a result of using the `++` operator, the `int`
2192
- argument will have value zero.[^12]
2193
 
2194
  [*Example 1*:
2195
 
2196
  ``` cpp
2197
  struct X {
@@ -2216,102 +2707,17 @@ void f(X a, Y b) {
2216
  }
2217
  ```
2218
 
2219
  — *end example*]
2220
 
2221
- The prefix and postfix decrement operators `-{-}` are handled
2222
- analogously.
2223
-
2224
- ### User-defined literals <a id="over.literal">[[over.literal]]</a>
2225
-
2226
- ``` bnf
2227
- literal-operator-id:
2228
- 'operator' string-literal identifier
2229
- 'operator' user-defined-string-literal
2230
- ```
2231
-
2232
- The *string-literal* or *user-defined-string-literal* in a
2233
- *literal-operator-id* shall have no *encoding-prefix* and shall contain
2234
- no characters other than the implicit terminating `'\0'`. The
2235
- *ud-suffix* of the *user-defined-string-literal* or the *identifier* in
2236
- a *literal-operator-id* is called a *literal suffix identifier*. Some
2237
- literal suffix identifiers are reserved for future standardization; see 
2238
- [[usrlit.suffix]]. A declaration whose *literal-operator-id* uses such a
2239
- literal suffix identifier is ill-formed, no diagnostic required.
2240
-
2241
- A declaration whose *declarator-id* is a *literal-operator-id* shall be
2242
- a declaration of a namespace-scope function or function template (it
2243
- could be a friend function ([[class.friend]])), an explicit
2244
- instantiation or specialization of a function template, or a
2245
- *using-declaration* ([[namespace.udecl]]). A function declared with a
2246
- *literal-operator-id* is a *literal operator*. A function template
2247
- declared with a *literal-operator-id* is a *literal operator template*.
2248
-
2249
- The declaration of a literal operator shall have a
2250
- *parameter-declaration-clause* equivalent to one of the following:
2251
-
2252
- ``` cpp
2253
- const char*
2254
- unsigned long long int
2255
- long double
2256
- char
2257
- wchar_t
2258
- char16_t
2259
- char32_t
2260
- const char*, std::size_t
2261
- const wchar_t*, std::size_t
2262
- const char16_t*, std::size_t
2263
- const char32_t*, std::size_t
2264
- ```
2265
-
2266
- If a parameter has a default argument ([[dcl.fct.default]]), the
2267
- program is ill-formed.
2268
-
2269
- A *raw literal operator* is a literal operator with a single parameter
2270
- whose type is `const char*`.
2271
-
2272
- The declaration of a literal operator template shall have an empty
2273
- *parameter-declaration-clause* and its *template-parameter-list* shall
2274
- have a single *template-parameter* that is a non-type template parameter
2275
- pack ([[temp.variadic]]) with element type `char`.
2276
-
2277
- Literal operators and literal operator templates shall not have C
2278
- language linkage.
2279
-
2280
- [*Note 1*: Literal operators and literal operator templates are usually
2281
- invoked implicitly through user-defined literals ([[lex.ext]]).
2282
- However, except for the constraints described above, they are ordinary
2283
- namespace-scope functions and function templates. In particular, they
2284
- are looked up like ordinary functions and function templates and they
2285
- follow the same overload resolution rules. Also, they can be declared
2286
- `inline` or `constexpr`, they may have internal or external linkage,
2287
- they can be called explicitly, their addresses can be taken,
2288
- etc. — *end note*]
2289
-
2290
- [*Example 1*:
2291
-
2292
- ``` cpp
2293
- void operator "" _km(long double); // OK
2294
- string operator "" _i18n(const char*, std::size_t); // OK
2295
- template <char...> double operator "" _\u03C0(); // OK: UCN for lowercase pi
2296
- float operator ""_e(const char*); // OK
2297
- float operator ""E(const char*); // error: reserved literal suffix~([usrlit.suffix], [lex.ext])
2298
- double operator""_Bq(long double); // OK: does not use the reserved identifier _Bq~([lex.name])
2299
- double operator"" _Bq(long double); // uses the reserved identifier _Bq~([lex.name])
2300
- float operator " " B(const char*); // error: non-empty string-literal
2301
- string operator "" 5X(const char*, std::size_t); // error: invalid literal suffix identifier
2302
- double operator "" _miles(double); // error: invalid parameter-declaration-clause
2303
- template <char...> int operator "" _j(const char*); // error: invalid parameter-declaration-clause
2304
- extern "C" void operator "" _m(long double); // error: C language linkage
2305
- ```
2306
-
2307
- — *end example*]
2308
 
2309
  ## Built-in operators <a id="over.built">[[over.built]]</a>
2310
 
2311
  The candidate operator functions that represent the built-in operators
2312
- defined in Clause  [[expr]] are specified in this subclause. These
2313
  candidate functions participate in the operator overload resolution
2314
  process as described in  [[over.match.oper]] and are used for no other
2315
  purpose.
2316
 
2317
  [*Note 1*: Because built-in operators take only operands with non-class
@@ -2323,27 +2729,26 @@ appropriate for the operator, or when an operand has an enumeration type
2323
  that can be converted to a type appropriate for the operator. Also note
2324
  that some of the candidate operator functions given in this subclause
2325
  are more permissive than the built-in operators themselves. As described
2326
  in  [[over.match.oper]], after a built-in operator is selected by
2327
  overload resolution the expression is subject to the requirements for
2328
- the built-in operator given in Clause  [[expr]], and therefore to any
2329
  additional semantic constraints given there. If there is a user-written
2330
  candidate with the same name and parameter types as a built-in candidate
2331
  operator function, the built-in operator function is hidden and is not
2332
  included in the set of candidate functions. — *end note*]
2333
 
2334
  In this subclause, the term *promoted integral type* is used to refer to
2335
- those integral types which are preserved by integral promotion (
2336
- [[conv.prom]]) (including e.g. `int` and `long` but excluding e.g.
2337
- `char`). Similarly, the term *promoted arithmetic type* refers to
2338
- floating types plus promoted integral types.
2339
 
2340
- [*Note 2*: In all cases where a promoted integral type or promoted
2341
- arithmetic type is required, an operand of enumeration type will be
2342
- acceptable by way of the integral promotions. — *end note*]
2343
 
2344
- In the remainder of this section, *vq* represents either `volatile` or
2345
  no cv-qualifier.
2346
 
2347
  For every pair (`T`, *vq*), where `T` is an arithmetic type other than
2348
  `bool`, there exist candidate operator functions of the form
2349
 
@@ -2389,12 +2794,12 @@ For every type `T` there exist candidate operator functions of the form
2389
 
2390
  ``` cpp
2391
  T* operator+(T*);
2392
  ```
2393
 
2394
- For every promoted arithmetic type `T`, there exist candidate operator
2395
- functions of the form
2396
 
2397
  ``` cpp
2398
  T operator+(T);
2399
  T operator-(T);
2400
  ```
@@ -2417,28 +2822,43 @@ cv12 T& operator->*(cv1 C1*, cv2 T C2::*);
2417
 
2418
  where *cv12* is the union of *cv1* and *cv2*. The return type is shown
2419
  for exposition only; see  [[expr.mptr.oper]] for the determination of
2420
  the operator’s result type.
2421
 
2422
- For every pair of promoted arithmetic types `L` and `R`, there exist
2423
- candidate operator functions of the form
 
2424
 
2425
  ``` cpp
2426
  LR operator*(L, R);
2427
  LR operator/(L, R);
2428
  LR operator+(L, R);
2429
  LR operator-(L, R);
 
 
2430
  bool operator<(L, R);
2431
  bool operator>(L, R);
2432
  bool operator<=(L, R);
2433
  bool operator>=(L, R);
2434
- bool operator==(L, R);
2435
- bool operator!=(L, R);
2436
  ```
2437
 
2438
- where `LR` is the result of the usual arithmetic conversions between
2439
- types `L` and `R`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2440
 
2441
  For every cv-qualified or cv-unqualified object type `T` there exist
2442
  candidate operator functions of the form
2443
 
2444
  ``` cpp
@@ -2458,20 +2878,23 @@ std::ptrdiff_t operator-(T, T);
2458
 
2459
  For every `T`, where `T` is an enumeration type or a pointer type, there
2460
  exist candidate operator functions of the form
2461
 
2462
  ``` cpp
 
 
2463
  bool operator<(T, T);
2464
  bool operator>(T, T);
2465
  bool operator<=(T, T);
2466
  bool operator>=(T, T);
2467
- bool operator==(T, T);
2468
- bool operator!=(T, T);
2469
  ```
2470
 
2471
- For every pointer to member type `T` or type `std::nullptr_t` there
2472
- exist candidate operator functions of the form
 
 
2473
 
2474
  ``` cpp
2475
  bool operator==(T, T);
2476
  bool operator!=(T, T);
2477
  ```
@@ -2486,16 +2909,16 @@ LR operator^(L, R);
2486
  LR operator|(L, R);
2487
  L operator<<(L, R);
2488
  L operator>>(L, R);
2489
  ```
2490
 
2491
- where `LR` is the result of the usual arithmetic conversions between
2492
- types `L` and `R`.
2493
 
2494
  For every triple (`L`, *vq*, `R`), where `L` is an arithmetic type, and
2495
- `R` is a promoted arithmetic type, there exist candidate operator
2496
- functions of the form
2497
 
2498
  ``` cpp
2499
  vq L& operator=(vq L&, R);
2500
  vq L& operator*=(vq L&, R);
2501
  vq L& operator/=(vq L&, R);
@@ -2508,12 +2931,13 @@ operator functions of the form
2508
 
2509
  ``` cpp
2510
  T*vq& operator=(T*vq&, T*);
2511
  ```
2512
 
2513
- For every pair (`T`, *vq*), where `T` is an enumeration or pointer to
2514
- member type, there exist candidate operator functions of the form
 
2515
 
2516
  ``` cpp
2517
  vq T& operator=(vq T&, T);
2518
  ```
2519
 
@@ -2545,19 +2969,20 @@ There also exist candidate operator functions of the form
2545
  bool operator!(bool);
2546
  bool operator&&(bool, bool);
2547
  bool operator||(bool, bool);
2548
  ```
2549
 
2550
- For every pair of promoted arithmetic types `L` and `R`, there exist
2551
- candidate operator functions of the form
 
2552
 
2553
  ``` cpp
2554
  LR operator?:(bool, L, R);
2555
  ```
2556
 
2557
- where `LR` is the result of the usual arithmetic conversions between
2558
- types `L` and `R`.
2559
 
2560
  [*Note 3*: As with all these descriptions of candidate functions, this
2561
  declaration serves only to describe the built-in operator for purposes
2562
  of overload resolution. The operator “`?:`” cannot be
2563
  overloaded. — *end note*]
@@ -2567,57 +2992,163 @@ enumeration type, there exist candidate operator functions of the form
2567
 
2568
  ``` cpp
2569
  T operator?:(bool, T, T);
2570
  ```
2571
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2572
  <!-- Link reference definitions -->
2573
  [basic.lookup]: basic.md#basic.lookup
2574
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
2575
  [basic.stc.dynamic]: basic.md#basic.stc.dynamic
2576
  [class.access]: class.md#class.access
2577
- [class.conv]: special.md#class.conv
2578
- [class.conv.ctor]: special.md#class.conv.ctor
2579
- [class.conv.fct]: special.md#class.conv.fct
2580
- [class.copy]: special.md#class.copy
 
2581
  [class.friend]: class.md#class.friend
 
 
2582
  [class.member.lookup]: class.md#class.member.lookup
2583
  [class.mfct]: class.md#class.mfct
2584
  [class.static]: class.md#class.static
2585
  [class.this]: class.md#class.this
2586
- [conv]: conv.md#conv
2587
- [conv.array]: conv.md#conv.array
2588
- [conv.bool]: conv.md#conv.bool
2589
- [conv.double]: conv.md#conv.double
2590
- [conv.fctptr]: conv.md#conv.fctptr
2591
- [conv.fpint]: conv.md#conv.fpint
2592
- [conv.fpprom]: conv.md#conv.fpprom
2593
- [conv.func]: conv.md#conv.func
2594
- [conv.integral]: conv.md#conv.integral
2595
- [conv.lval]: conv.md#conv.lval
2596
- [conv.mem]: conv.md#conv.mem
2597
- [conv.prom]: conv.md#conv.prom
2598
- [conv.ptr]: conv.md#conv.ptr
2599
- [conv.qual]: conv.md#conv.qual
2600
- [cpp]: cpp.md#cpp
 
2601
  [dcl.array]: dcl.md#dcl.array
 
2602
  [dcl.fct]: dcl.md#dcl.fct
2603
  [dcl.fct.def.delete]: dcl.md#dcl.fct.def.delete
2604
  [dcl.fct.default]: dcl.md#dcl.fct.default
 
2605
  [dcl.init]: dcl.md#dcl.init
2606
  [dcl.init.aggr]: dcl.md#dcl.init.aggr
2607
  [dcl.init.list]: dcl.md#dcl.init.list
2608
  [dcl.init.ref]: dcl.md#dcl.init.ref
2609
  [dcl.init.string]: dcl.md#dcl.init.string
 
 
2610
  [dcl.typedef]: dcl.md#dcl.typedef
2611
  [except.spec]: except.md#except.spec
2612
- [expr]: expr.md#expr
2613
  [expr.ass]: expr.md#expr.ass
 
2614
  [expr.call]: expr.md#expr.call
2615
  [expr.cast]: expr.md#expr.cast
 
2616
  [expr.cond]: expr.md#expr.cond
 
2617
  [expr.mptr.oper]: expr.md#expr.mptr.oper
2618
- [expr.prim]: expr.md#expr.prim
 
 
 
2619
  [expr.static.cast]: expr.md#expr.static.cast
2620
  [expr.sub]: expr.md#expr.sub
2621
  [expr.type.conv]: expr.md#expr.type.conv
2622
  [expr.unary.op]: expr.md#expr.unary.op
2623
  [lex.ext]: lex.md#lex.ext
@@ -2652,22 +3183,28 @@ T operator?:(bool, T, T);
2652
  [over.match.oper]: #over.match.oper
2653
  [over.match.ref]: #over.match.ref
2654
  [over.match.viable]: #over.match.viable
2655
  [over.oper]: #over.oper
2656
  [over.over]: #over.over
 
2657
  [over.ref]: #over.ref
2658
  [over.sub]: #over.sub
2659
  [over.unary]: #over.unary
2660
  [stmt.return]: stmt.md#stmt.return
2661
- [tab:over.conversions]: #tab:over.conversions
2662
- [tab:over.rel.op.func]: #tab:over.rel.op.func
2663
  [temp.arg.explicit]: temp.md#temp.arg.explicit
2664
  [temp.arg.nontype]: temp.md#temp.arg.nontype
 
 
 
2665
  [temp.deduct]: temp.md#temp.deduct
2666
  [temp.deduct.funcaddr]: temp.md#temp.deduct.funcaddr
 
 
 
2667
  [temp.func.order]: temp.md#temp.func.order
2668
  [temp.over]: temp.md#temp.over
 
2669
  [temp.variadic]: temp.md#temp.variadic
2670
  [usrlit.suffix]: library.md#usrlit.suffix
2671
 
2672
  [^1]: When a parameter type includes a function type, such as in the
2673
  case of a parameter type that is a pointer to function, the `const`
@@ -2677,12 +3214,12 @@ T operator?:(bool, T, T);
2677
 
2678
  [^2]: The process of argument deduction fully determines the parameter
2679
  types of the function template specializations, i.e., the parameters
2680
  of function template specializations contain no template parameter
2681
  types. Therefore, except where specified otherwise, function
2682
- template specializations and non-template functions ([[dcl.fct]])
2683
- are treated equivalently for the remainder of overload resolution.
2684
 
2685
  [^3]: Note that cv-qualifiers on the type of objects are significant in
2686
  overload resolution for both glvalue and class prvalue objects.
2687
 
2688
  [^4]: An implied object argument must be contrived to correspond to the
@@ -2705,29 +3242,26 @@ T operator?:(bool, T, T);
2705
  [^7]: If the value returned by the `operator->` function has class type,
2706
  this may result in selecting and calling another `operator->`
2707
  function. The process repeats until an `operator->` function returns
2708
  a value of non-class type.
2709
 
2710
- [^8]: According to  [[dcl.fct.default]], parameters following the
2711
- *(m+1)*-st parameter must also have default arguments.
2712
-
2713
- [^9]: If a function is a static member function, this definition means
2714
  that the first argument, the implied object argument, has no effect
2715
  in the determination of whether the function is better or worse than
2716
  any other function.
2717
 
2718
- [^10]: The algorithm for selecting the best viable function is linear in
2719
  the number of viable functions. Run a simple tournament to find a
2720
  function `W` that is not worse than any opponent it faced. Although
2721
  another function `F` that `W` did not face might be at least as good
2722
  as `W`, `F` cannot be the best function because at some point in the
2723
  tournament `F` encountered another function `G` such that `F` was
2724
- not better than `G`. Hence, `W` is either the best function or there
2725
  is no best function. So, make a second pass over the viable
2726
  functions to verify that `W` is better than all other functions.
2727
 
2728
- [^11]: Since there are no parameters of array type, this will only occur
2729
  as the referenced type of a reference parameter.
2730
 
2731
- [^12]: Calling `operator++` explicitly, as in expressions like
2732
  `a.operator++(2)`, has no special properties: The argument to
2733
  `operator++` is `2`.
 
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);
 
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);
 
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*);
 
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
 
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
 
 
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);
 
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;
 
317
  context ill-formed. — *end note*]
318
 
319
  Overload resolution selects the function to call in seven distinct
320
  contexts within the language:
321
 
322
+ - invocation of a function named in the function call syntax
323
+ [[over.call.func]];
324
  - invocation of a function call operator, a pointer-to-function
325
  conversion function, a reference-to-pointer-to-function conversion
326
  function, or a reference-to-function conversion function on a class
327
+ object named in the function call syntax [[over.call.object]];
328
+ - invocation of the operator referenced in an expression
329
+ [[over.match.oper]];
330
+ - invocation of a constructor for default- or direct-initialization
331
+ [[dcl.init]] of a class object [[over.match.ctor]];
332
+ - invocation of a user-defined conversion for copy-initialization
333
+ [[dcl.init]] of a class object [[over.match.copy]];
334
  - invocation of a conversion function for initialization of an object of
335
+ a non-class type from an expression of class type [[over.match.conv]];
336
+ and
337
+ - invocation of a conversion function for conversion in which a
338
+ reference [[dcl.init.ref]] will be directly bound [[over.match.ref]].
 
339
 
340
  Each of these contexts defines the set of candidate functions and the
341
  list of arguments in its own unique way. But, once the candidate
342
  functions and argument lists have been identified, the selection of the
343
  best function is the same in all cases:
344
 
345
  - First, a subset of the candidate functions (those that have the proper
346
  number of arguments and meet certain other conditions) is selected to
347
+ form a set of viable functions [[over.match.viable]].
348
  - Then the best viable function is selected based on the implicit
349
+ conversion sequences [[over.best.ics]] needed to match each argument
350
+ to the corresponding parameter of each viable function.
351
 
352
  If a best viable function exists and is unique, overload resolution
353
  succeeds and produces it as the result. Otherwise overload resolution
354
  fails and the invocation is ill-formed. When overload resolution
355
+ succeeds, and the best viable function is not accessible
356
+ [[class.access]] in the context in which it is used, the program is
357
  ill-formed.
358
 
359
+ Overload resolution results in a *usable candidate* if overload
360
+ 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
 
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]]).
 
440
 
441
  class C : T {
442
  public:
443
  C(int);
444
  };
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 {
478
+ A(); // #1
479
+ A(A &&); // #2
480
+ template<typename T> A(T &&); // #3
481
+ };
482
+ struct B : A {
483
+ using A::A;
484
+ B(const B &); // #4
485
+ B(B &&) = default; // #5, implicitly deleted
486
+
487
+ struct X { X(X &&) = delete; } x;
488
+ };
489
+ extern B b1;
490
+ B b2 = static_cast<B&&>(b1); // calls #4: #1 is not viable, #2, #3, and #5 are not candidates
491
+ struct C { operator B&&(); };
492
+ B b3 = C(); // calls #4
493
+ ```
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
  ```
504
 
505
+ if the *postfix-expression* names at least one function or function
506
+ 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>
 
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
584
+ operator conversion-type-id '( )' cv-qualifier-seqₒₚₜ ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ ';'
585
  ```
586
 
587
+ where the optional *cv-qualifier-seq* is the same cv-qualification as,
588
+ or a greater cv-qualification than, cv, and where *conversion-type-id*
589
+ denotes the type “pointer to function of (`P₁`, …, `Pₙ`) returning `R`”,
590
+ or the type “reference to pointer to function of (`P₁`, …, `Pₙ`)
591
+ returning `R`”, or the type “reference to function of (`P₁`, …, `Pₙ`)
592
+ returning `R`”, a *surrogate call function* with the unique name
593
+ *call-function* and having the form
594
 
595
  ``` bnf
596
+ 'R' *call-function* '(' conversion-type-id \ %
597
  'F, P₁ a₁, …, Pₙ aₙ)' '{ return F (a₁, …, aₙ); }'
598
  ```
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
 
 
635
 
636
  #### Operators in expressions <a id="over.match.oper">[[over.match.oper]]</a>
637
 
638
  If no operand of an operator in an expression has a type that is a class
639
  or an enumeration, the operator is assumed to be a built-in operator and
640
+ interpreted according to [[expr.compound]].
641
 
642
  [*Note 1*: Because `.`, `.*`, and `::` cannot be overloaded, these
643
+ operators are always built-in operators interpreted according to
644
+ [[expr.compound]]. `?:` cannot be overloaded, but the rules in this
645
+ subclause are used to determine the conversions to be applied to the
646
+ second and third operands when they have class or enumeration type
647
+ [[expr.cond]]. — *end note*]
648
 
649
  [*Example 1*:
650
 
651
  ``` cpp
652
  struct String {
 
655
  operator const char* ();
656
  };
657
  String operator + (const String&, const String&);
658
 
659
  void f() {
660
+ const char* p= "one" + "two"; // error: cannot add two pointers; overloaded operator+ not considered
661
+ // because neither operand has class or enumeration type
662
  int I = 1 + 1; // always evaluates to 2 even if class or enumeration types exist
663
  // that would perform the operation.
664
  }
665
  ```
666
 
 
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
676
+ function-call notation as summarized in [[over.match.oper]] (where `@`
677
+ denotes one of the operators covered in the specified subclause).
678
+ However, the operands are sequenced in the order prescribed for the
679
+ built-in operator [[expr.compound]].
680
 
681
+ **Table: Relationship between operator and function call notation** <a id="over.match.oper">[over.match.oper]</a>
682
 
683
  | Subclause | Expression | As member function | As non-member function |
684
  | ------------ | ---------- | ------------------- | ---------------------- |
685
  | (a)} |
686
  | (a, b)} |
 
688
  | [[over.sub]] | `a[b]` | `(a).operator[](b)` | |
689
  | [[over.ref]] | `a->` | `(a).operator->( )` | |
690
  | (a, 0)} |
691
 
692
 
693
+ For a unary operator `@` with an operand of type *cv1* `T1`, and for a
694
+ 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
 
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
749
  a type match with the left-most parameter of a built-in candidate.
750
 
751
  For all other operators, no such restrictions apply.
752
 
753
+ The set of candidate functions for overload resolution for some operator
754
+ `@` is the union of the member candidates, the non-member candidates,
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 {
 
772
  }
773
  ```
774
 
775
  — *end example*]
776
 
777
+ If a rewritten `operator<=>` candidate is selected by overload
778
+ resolution for an operator `@`, `x @ y` is interpreted as
779
+ `0 @ (y <=> x)` if the selected candidate is a synthesized candidate
780
+ with reversed order of parameters, or `(x <=> y) @ 0` otherwise, using
781
+ the selected rewritten `operator<=>` candidate. Rewritten candidates for
782
+ the operator `@` are not considered in the context of the resulting
783
+ expression.
784
+
785
+ If a rewritten `operator==` candidate is selected by overload resolution
786
+ for an operator `@`, its return type shall be cv `bool`, and `x @ y` is
787
+ interpreted as:
788
+
789
+ - if `@` is `!=` and the selected candidate is a synthesized candidate
790
+ with reversed order of parameters, `!(y == x)`,
791
+ - otherwise, if `@` is `!=`, `!(x == y)`,
792
+ - otherwise (when `@` is `==`), `y == x`,
793
+
794
+ in each case using the selected rewritten `operator==` candidate.
795
+
796
  If a built-in candidate is selected by overload resolution, the operands
797
  of class type are converted to the types of the corresponding parameters
798
  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 {
 
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]].
830
 
831
+ [*Note 3*:
832
 
833
  The lookup rules for operators in expressions are different than the
834
  lookup rules for operator function names in a function call, as shown in
835
  the following example:
836
 
 
853
 
854
  — *end note*]
855
 
856
  #### Initialization by constructor <a id="over.match.ctor">[[over.match.ctor]]</a>
857
 
858
+ When objects of class type are direct-initialized [[dcl.init]],
859
+ copy-initialized from an expression of the same or a derived class type
860
+ [[dcl.init]], or default-initialized [[dcl.init]], overload resolution
861
+ selects the constructor. For direct-initialization or
862
  default-initialization that is not in the context of
863
  copy-initialization, the candidate functions are all the constructors of
864
+ the class of the object being initialized. For copy-initialization
865
+ (including default initialization in the context of
866
+ copy-initialization), the candidate functions are all the converting
867
+ constructors [[class.conv.ctor]] of that class. The argument list is the
868
  *expression-list* or *assignment-expression* of the *initializer*.
869
 
870
  #### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
871
 
872
  Under the conditions specified in  [[dcl.init]], as part of a
 
880
  corresponding non-reference copy-initialization. — *end note*]
881
 
882
  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
 
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
973
+ according to the rules in this subclause or when forming a
974
+ list-initialization sequence according to [[over.ics.list]], overload
975
+ resolution selects the constructor in two phases:
976
 
977
+ - If the initializer list is not empty or `T` has no default
978
+ constructor, overload resolution is first performed where the
979
+ candidate functions are the initializer-list constructors
980
+ [[dcl.init.list]] of the class `T` and the argument list consists of
981
+ the initializer list as a single argument.
982
+ - Otherwise, or if no viable initializer-list constructor is found,
983
+ overload resolution is performed again, where the candidate functions
984
+ are all the constructors of the class `T` and the argument list
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
1000
+ class template `C`, a set of functions and function templates, called
1001
+ the guides of `C`, is formed comprising:
1002
 
1003
+ - If `C` is defined, for each constructor of `C`, a function template
1004
+ with the following properties:
1005
+ - The template parameters are the template parameters of `C` followed
1006
+ by the template parameters (including default template arguments) of
1007
+ the constructor, if any.
 
1008
  - The types of the function parameters are those of the constructor.
1009
  - The return type is the class template specialization designated by
1010
+ `C` and template arguments corresponding to the template parameters
1011
+ of `C`.
1012
+ - If `C` is not defined or does not declare any constructors, an
1013
+ additional function template derived as above from a hypothetical
1014
+ constructor `C()`.
1015
  - An additional function template derived as above from a hypothetical
1016
  constructor `C(C)`, called the *copy deduction candidate*.
1017
  - For each *deduction-guide*, a function or function template with the
1018
  following properties:
1019
  - The template parameters, if any, and function parameters are those
1020
  of the *deduction-guide*.
1021
  - The return type is the *simple-template-id* of the
1022
  *deduction-guide*.
1023
 
1024
+ In addition, if `C` is defined and its definition satisfies the
1025
+ conditions for an aggregate class [[dcl.init.aggr]] with the assumption
1026
+ that any dependent base class has no virtual functions and no virtual
1027
+ base classes, and the initializer is a non-empty *braced-init-list* or
1028
+ parenthesized *expression-list*, and there are no *deduction-guide*s for
1029
+ `C`, the set contains an additional function template, called the
1030
+ *aggregate deduction candidate*, defined as follows. Let x₁, …, xₙ be
1031
+ 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
+
1067
+ ``` bnf
1068
+ typenameₒₚₜ nested-name-specifierₒₚₜ templateₒₚₜ simple-template-id
1069
+ ```
1070
+
1071
+ 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
1086
+ deductions or (recursively) in their default template arguments,
1087
+ followed by the template parameters of `f` that were not deduced
1088
+ (including their default template arguments), otherwise `f'` is not 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
1103
+
1104
+ ``` cpp
1105
+ template <typename> class AA;
1106
+ ```
1107
+
1108
+ with a single partial specialization whose template parameter list is
1109
+ that of `A` and whose template argument list is a specialization of `A`
1110
+ with the template argument list of `A` [[temp.dep.type]], `AA<T>`
1111
+ matches the partial specialization.
1112
+
1113
  Initialization and overload resolution are performed as described in
1114
  [[dcl.init]] and [[over.match.ctor]], [[over.match.copy]], or
1115
  [[over.match.list]] (as appropriate for the type of initialization
1116
+ performed) for an object of a hypothetical class type, where the guides
1117
+ of the template named by the placeholder are considered to be the
1118
  constructors of that class type for the purpose of forming an overload
1119
  set, and the initializer is provided by the context in which class
1120
+ template argument deduction was performed. The following exceptions
1121
+ apply:
1122
+
1123
+ - The first phase in [[over.match.list]] (considering initializer-list
1124
+ constructors) is omitted if the initializer list consists of a single
1125
+ expression of type cv `U`, where `U` is, or is derived from, a
1126
+ specialization of the class template directly or indirectly named by
1127
+ the placeholder.
1128
+ - During template argument deduction for the aggregate deduction
1129
+ candidate, the number of elements in a trailing parameter pack is only
1130
+ deduced from the number of remaining function arguments if it is not
1131
+ otherwise deduced.
1132
+
1133
+ 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 {
 
1164
  template <class U> using TA = T;
1165
  template <class U> B(U, TA<U>);
1166
  };
1167
 
1168
  B b{(int*)0, (char*)0}; // OK, deduces B<char*>
1169
+
1170
+ template <typename T>
1171
+ struct S {
1172
+ T x;
1173
+ T y;
1174
+ };
1175
+
1176
+ template <typename T>
1177
+ struct C {
1178
+ S<T> s;
1179
+ T t;
1180
+ };
1181
+
1182
+ template <typename T>
1183
+ struct D {
1184
+ S<int> s;
1185
+ T t;
1186
+ };
1187
+
1188
+ C c1 = {1, 2}; // error: deduction failed
1189
+ C c2 = {1, 2, 3}; // error: deduction failed
1190
+ C c3 = {{1u, 2u}, 3}; // OK, deduces C<int>
1191
+
1192
+ D d1 = {1, 2}; // error: deduction failed
1193
+ D d2 = {1, 2, 3}; // OK, braces elided, deduces D<int>
1194
+
1195
+ template <typename T>
1196
+ struct E {
1197
+ T t;
1198
+ decltype(t) t2;
1199
+ };
1200
+
1201
+ E e1 = {1, 2}; // OK, deduces E<int>
1202
+
1203
+ template <typename... T>
1204
+ struct Types {};
1205
+
1206
+ template <typename... T>
1207
+ struct F : Types<T...>, T... {};
1208
+
1209
+ struct X {};
1210
+ struct Y {};
1211
+ struct Z {};
1212
+ struct W { operator Y(); };
1213
+
1214
+ F f1 = {Types<X, Y, Z>{}, {}, {}}; // OK, F<X, Y, Z> deduced
1215
+ 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
+ };
1227
+ template<class T, class U>
1228
+ C(T, U) -> C<T, std::type_identity_t<U>>; // #2
1229
+
1230
+ template<class V> using A = C<V *, V *>;
1231
+ template<std::integral W> using B = A<W>;
1232
+
1233
+ int i{};
1234
+ double d{};
1235
+ A a1(&i, &i); // deduces A<int>
1236
+ A a2(i, i); // error: cannot deduce V * from i
1237
+ A a3(&i, &d); // error: #1: cannot deduce (V*, V*) from (int *, double *)
1238
+ // #2: cannot deduce A<V> from C<int *, double *>
1239
+ B b1(&i, &i); // deduces B<int>
1240
+ B b2(&d, &d); // error: cannot deduce B<W> from C<double *, double *>
1241
+ ```
1242
+
1243
+ Possible exposition-only implementation of the above procedure:
1244
+
1245
+ ``` cpp
1246
+ // The following concept ensures a specialization of A is deduced.
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 *>>
1258
+ auto f1_prime(V *, V*) -> C<V *, V *>;
1259
+
1260
+ // f2 is formed from the deduction-guide #2 of C
1261
+ template<class T, class U> auto f2(T, U) -> C<T, std::type_identity_t<U>>;
1262
+
1263
+ // Deducing arguments for C<T, std::type_identity_t<U>> from C<V *, V*> deduces T as V *;
1264
+ // f2' is obtained by transforming f2 as described by the above procedure.
1265
+ template<class V, class U>
1266
+ requires deduces_A<C<V *, std::type_identity_t<U>>>
1267
+ auto f2_prime(V *, U) -> C<V *, std::type_identity_t<U>>;
1268
+
1269
+ // The following concept ensures a specialization of B is deduced.
1270
+ template <class> class BB;
1271
+ template <class V> class BB<B<V>> { };
1272
+ template <class T> concept deduces_B = requires { sizeof(BB<T>); };
1273
+
1274
+ // The guides for B derived from the above f1' and f2' for A are as follows:
1275
+ template<std::integral W>
1276
+ requires deduces_A<C<W *, W *>> && deduces_B<C<W *, W *>>
1277
+ auto f1_prime_for_B(W *, W *) -> C<W *, W *>;
1278
+
1279
+ template<std::integral W, class U>
1280
+ requires deduces_A<C<W *, std::type_identity_t<U>>> &&
1281
+ deduces_B<C<W *, std::type_identity_t<U>>>
1282
+ auto f2_prime_for_B(W *, U) -> C<W *, std::type_identity_t<U>>;
1283
  ```
1284
 
1285
  — *end example*]
1286
 
1287
  ### Viable functions <a id="over.match.viable">[[over.match.viable]]</a>
1288
 
1289
+ From the set of candidate functions constructed for a given context
1290
+ [[over.match.funcs]], a set of viable functions is chosen, from which
1291
  the best function will be selected by comparing argument conversion
1292
+ sequences and associated constraints [[temp.constr.decl]] for the best
1293
+ fit [[over.match.best]]. The selection of viable functions considers
1294
+ 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>
 
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
 
1365
  ```
1366
 
1367
  — *end example*]
1368
  or, if not that,
1369
  - the context is an initialization by conversion function for direct
1370
+ reference binding [[over.match.ref]] of a reference to function type,
1371
+ the return type of `F1` is the same kind of reference (lvalue or
1372
+ rvalue) as the reference being initialized, and the return type of
1373
+ `F2` is not
1374
  \[*Example 2*:
1375
  ``` cpp
1376
  template <class T> struct A {
1377
  operator T&(); // #1
1378
  operator T&&(); // #2
 
1389
  template specialization, or, if not that,
1390
  - `F1` and `F2` are function template specializations, and the function
1391
  template for `F1` is more specialized than the template for `F2`
1392
  according to the partial ordering rules described in 
1393
  [[temp.func.order]], or, if not that,
1394
+ - `F1` and `F2` are non-template functions with the same
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
+ };
1406
+
1407
+ struct B: A {
1408
+ using A::A;
1409
+ B();
1410
+ };
1411
+
1412
+ int main() {
1413
+ B b; // OK, B::B()
1414
+ }
1415
+ ```
1416
+
1417
+ — *end example*]
1418
+ or, if not that,
1419
+ - `F2` is a rewritten candidate [[over.match.oper]] and `F1` is not
1420
+ \[*Example 4*:
1421
+ ``` cpp
1422
+ struct S {
1423
+ friend auto operator<=>(const S&, const S&) = default; // #1
1424
+ friend bool operator<(const S&, const S&); // #2
1425
+ };
1426
+ bool b = S() < S(); // calls #2
1427
+ ```
1428
+
1429
+ — *end example*]
1430
+ or, if not that,
1431
+ - `F1` and `F2` are rewritten candidates, and `F2` is a synthesized
1432
+ candidate with reversed order of parameters and `F1` is not
1433
+ \[*Example 5*:
1434
+ ``` cpp
1435
+ struct S {
1436
+ friend std::weak_ordering operator<=>(const S&, int); // #1
1437
+ friend std::weak_ordering operator<=>(int, const S&); // #2
1438
+ };
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
1449
  generated from a constructor template.
1450
+ \[*Example 6*:
1451
  ``` cpp
1452
  template <class T> struct A {
1453
  using value_type = T;
1454
  A(value_type); // #1
1455
  A(const A&); // #2
 
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);
1486
  void Fcn(int*, int);
1487
 
 
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 {
1515
  extern "C" void f(int = 5);
1516
  }
 
1521
  using A::f;
1522
  using B::f;
1523
 
1524
  void use() {
1525
  f(3); // OK, default argument was not used for viability
1526
+ f(); // error: found default argument twice
1527
  }
1528
  ```
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
+
1545
+ [*Note 1*: Other properties, such as the lifetime, storage class,
1546
+ alignment, accessibility of the argument, whether the argument is a
1547
+ bit-field, and whether a function is deleted [[dcl.fct.def.delete]], are
1548
+ ignored. So, although an implicit conversion sequence can be defined for
1549
+ a given argument-parameter pair, the conversion from the argument to the
1550
+ parameter might still be ill-formed in the final
1551
+ analysis. — *end note*]
1552
 
1553
  A well-formed implicit conversion sequence is one of the following
1554
  forms:
1555
 
1556
+ - a standard conversion sequence [[over.ics.scs]],
1557
+ - a user-defined conversion sequence [[over.ics.user]], or
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
 
1574
  is the first parameter of a constructor of class `X`, and the
1575
  conversion is to `X` or reference to cv `X`,
1576
 
1577
  user-defined conversion sequences are not considered.
1578
 
1579
+ [*Note 2*: These rules prevent more than one user-defined conversion
1580
  from being applied during overload resolution, thereby avoiding infinite
1581
  recursion. — *end note*]
1582
 
1583
  [*Example 1*:
1584
 
1585
  ``` cpp
1586
  struct Y { Y(int); };
1587
  struct A { operator int(); };
1588
  Y y1 = A(); // error: A::operator int() is not a candidate
1589
 
1590
+ struct X { X(); };
1591
  struct B { operator X(); };
1592
  B b;
1593
+ X x{{b}}; // error: B::operator X() is not a candidate
1594
  ```
1595
 
1596
  — *end example*]
1597
 
1598
  For the case where the parameter type is a reference, see 
 
1602
  sequence models a copy-initialization of the parameter from the argument
1603
  expression. The implicit conversion sequence is the one required to
1604
  convert the argument expression to a prvalue of the type of the
1605
  parameter.
1606
 
1607
+ [*Note 3*: When the parameter has a class type, this is a conceptual
1608
+ conversion defined for the purposes of [[over]]; the actual
1609
  initialization is defined in terms of constructors and is not a
1610
  conversion. — *end note*]
1611
 
1612
  Any difference in top-level cv-qualification is subsumed by the
1613
  initialization itself and does not constitute a conversion.
 
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
1641
  parameter type, an implicit conversion sequence cannot be formed.
1642
 
1643
+ If there are multiple well-formed implicit conversion sequences
1644
+ converting the argument to the parameter type, the implicit conversion
1645
+ sequence associated with the parameter is defined to be the unique
1646
+ 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*:
 
1662
  class B { operator A (); };
1663
  class C { C (B&); };
1664
  void f(A) { }
1665
  void f(C) { }
1666
  B b;
1667
+ f(b); // error: ambiguous because there is a conversion b → C (via constructor)
1668
  // and an (ambiguous) conversion b → A (via constructor or conversion function)
1669
  void f(B) { }
1670
  f(b); // OK, unambiguous
1671
  ```
1672
 
 
1681
  The three forms of implicit conversion sequences mentioned above are
1682
  defined in the following subclauses.
1683
 
1684
  ##### Standard conversion sequences <a id="over.ics.scs">[[over.ics.scs]]</a>
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*]
 
1704
 
1705
+ Each conversion in [[over.ics.scs]] also has an associated rank (Exact
1706
+ Match, Promotion, or Conversion). These are used to rank standard
1707
+ conversion sequences [[over.ics.rank]]. The rank of a conversion
1708
+ sequence is determined by considering the rank of each conversion in the
1709
+ sequence and the rank of any reference binding [[over.ics.ref]]. If any
1710
+ of those has Conversion rank, the sequence has Conversion rank;
1711
+ otherwise, if any of those has Promotion rank, the sequence has
1712
+ Promotion rank; otherwise, the sequence has Exact Match rank.
 
1713
 
1714
+ **Table: Conversions** <a id="over.ics.scs">[over.ics.scs]</a>
1715
 
1716
  | Conversion | Category | Rank | Subclause |
1717
  | ----------------------- | -------- | ---- | ----------------- |
1718
  | No conversions required | Identity | | |
1719
  | Integral promotions | | | [[conv.prom]] |
1720
  | Integral conversions | | | [[conv.integral]] |
1721
 
1722
 
1723
  ##### User-defined conversion sequences <a id="over.ics.user">[[over.ics.user]]</a>
1724
 
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,
1739
+ the special rules for initialization by user-defined conversion apply
1740
+ when selecting the best user-defined conversion for a user-defined
1741
+ conversion sequence (see  [[over.match.best]] and  [[over.best.ics]]).
1742
 
1743
  If the user-defined conversion is specified by a specialization of a
1744
  conversion function template, the second standard conversion sequence
1745
  shall have exact match rank.
1746
 
 
1756
  call is matched with the ellipsis parameter specification of the
1757
  function called (see  [[expr.call]]).
1758
 
1759
  ##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
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
 
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
1788
  argument expression to the referenced type according to 
1789
  [[over.best.ics]]. Conceptually, this conversion sequence corresponds to
1790
  copy-initializing a temporary of the referenced type with the argument
1791
  expression. Any difference in top-level cv-qualification is subsumed by
1792
  the initialization itself and does not constitute a conversion.
1793
 
1794
  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
 
1806
  Other restrictions on binding a reference to a particular argument that
1807
  are not based on the types of the reference and the argument do not
1808
+ affect the formation of an implicit conversion sequence, however.
1809
 
1810
  [*Example 5*: A function with an “lvalue reference to `int`” parameter
1811
  can be a viable candidate even if the corresponding argument is an `int`
1812
  bit-field. The formation of implicit conversion sequences treats the
1813
  `int` bit-field as an `int` lvalue and finds an exact match with the
1814
  parameter. If the function is selected by overload resolution, the call
1815
  will nonetheless be ill-formed because of the prohibition on binding a
1816
+ non-`const` lvalue reference to a bit-field
1817
+ [[dcl.init.ref]]. — *end example*]
1818
 
1819
  ##### List-initialization sequence <a id="over.ics.list">[[over.ics.list]]</a>
1820
 
1821
+ When an argument is an initializer list [[dcl.init.list]], it is not an
1822
+ expression and special rules apply for converting it to a parameter
1823
  type.
1824
 
1825
+ If the initializer list is a *designated-initializer-list*, a conversion
1826
+ 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]].
1838
+
1839
+ [*Example 6*:
1840
+
1841
+ ``` cpp
1842
+ struct A { int x, y; };
1843
+ struct B { int y, x; };
1844
+ void f(A a, int); // #1
1845
+ void f(B b, ...); // #2
1846
+ void g(A a); // #3
1847
+ void g(B b); // #4
1848
+ void h() {
1849
+ f({.x = 1, .y = 2}, 0); // OK; calls #1
1850
+ f({.y = 2, .x = 1}, 0); // error: selects #1, initialization of a fails
1851
+ // due to non-matching member order[dcl.init.list]
1852
+ g({.x = 1, .y = 2}); // error: ambiguous between #3 and #4
1853
+ }
1854
+ ```
1855
+
1856
+ — *end example*]
1857
+
1858
+ — *end note*]
1859
+
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
1874
  elements, the identity conversion. This conversion can be a user-defined
1875
  conversion even in the context of a call to an initializer-list
1876
  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
 
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
1905
+ unknown bound of `X`”, if there exists an implicit conversion sequence
1906
+ from each element of the initializer list (and from `{}` in the former
1907
+ case if `N` exceeds the number of elements in the initializer list) to
1908
+ `X`, the implicit conversion sequence is the worst such implicit
1909
+ conversion sequence.
1910
 
1911
  Otherwise, if the parameter is a non-aggregate class `X` and overload
1912
  resolution per  [[over.match.list]] chooses a single best constructor
1913
  `C` of `X` to perform the initialization of an object of type `X` from
1914
  the argument initializer list:
 
1925
  the implicit conversion sequence is the ambiguous conversion sequence.
1926
  User-defined conversions are allowed for conversion of the initializer
1927
  list elements to the constructor parameter types except as noted in 
1928
  [[over.best.ics]].
1929
 
1930
+ [*Example 8*:
1931
 
1932
  ``` cpp
1933
  struct A {
1934
  A(std::initializer_list<int>);
1935
  };
 
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;
 
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
1993
  struct A {
1994
  int m1;
1995
  double m2;
 
2008
  Otherwise, if the parameter type is not a class:
2009
 
2010
  - if the initializer list has one element that is not itself an
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
 
 
2042
  S2, S1 and S2 are said to be *indistinguishable conversion sequences*.
2043
 
2044
  When comparing the basic forms of implicit conversion sequences (as
2045
  defined in  [[over.best.ics]])
2046
 
2047
+ - a standard conversion sequence [[over.ics.scs]] is a better conversion
2048
+ sequence than a user-defined conversion sequence or an ellipsis
2049
+ conversion sequence, and
2050
+ - a user-defined conversion sequence [[over.ics.user]] is a better
2051
+ conversion sequence than an ellipsis conversion sequence
2052
+ [[over.ics.ellipsis]].
2053
 
2054
  Two implicit conversion sequences of the same form are indistinguishable
2055
  conversion sequences unless one of the following rules applies:
2056
 
2057
  - List-initialization sequence `L1` is a better conversion sequence than
2058
  list-initialization sequence `L2` if
2059
  - `L1` converts to `std::initializer_list<X>` for some `X` and `L2`
2060
  does not, or, if not that,
2061
+ - `L1` and `L2` convert to arrays of the same element type, and either
2062
+ the number of elements n₁ initialized by `L1` is less than the
2063
+ number of elements n₂ initialized by `L2`, or n₁ = n₂ and `L2`
2064
+ converts to an array of unknown bound and `L1` does not,
2065
 
2066
  even if one of the other rules in this paragraph would otherwise
2067
  apply.
2068
  \[*Example 1*:
2069
  ``` cpp
 
2074
  void f2(std::pair<const char*, const char*>); // #3
2075
  void f2(std::initializer_list<std::string>); // #4
2076
  void g2() { f2({"foo","bar"}); } // chooses #4
2077
  ```
2078
 
2079
+ — *end example*]
2080
+ \[*Example 2*:
2081
+ ``` cpp
2082
+ void f(int (&&)[] ); // #1
2083
+ void f(double (&&)[] ); // #2
2084
+ void f(int (&&)[2]); // #3
2085
+
2086
+ f( {1} ); // Calls #1: Better than #2 due to conversion, better than #3 due to bounds
2087
+ f( {1.0} ); // Calls #2: Identity conversion is better than floating-integral conversion
2088
+ f( {1.0, 2.0} ); // Calls #2: Identity conversion is better than floating-integral conversion
2089
+ f( {1, 2} ); // Calls #3: Converting to array of known bound is better than to unknown bound,
2090
+ // and an identity conversion is better than floating-integral conversion
2091
+ ```
2092
+
2093
  — *end example*]
2094
  - Standard conversion sequence `S1` is a better conversion sequence than
2095
  standard conversion sequence `S2` if
2096
  - `S1` is a proper subsequence of `S2` (comparing the conversion
2097
  sequences in the canonical form defined by  [[over.ics.scs]],
 
2099
  sequence is considered to be a subsequence of any non-identity
2100
  conversion sequence) or, if not that,
2101
  - the rank of `S1` is better than the rank of `S2`, or `S1` and `S2`
2102
  have the same rank and are distinguishable by the rules in the
2103
  paragraph below, or, if not that,
2104
+ - `S1` and `S2` include reference bindings [[dcl.init.ref]] and
2105
+ neither refers to an implicit object parameter of a non-static
2106
+ member function declared without a *ref-qualifier*, and `S1` binds
2107
+ an rvalue reference to an rvalue and `S2` binds an lvalue reference
2108
+ \[*Example 3*:
2109
  ``` cpp
2110
  int i;
2111
  int f1();
2112
  int&& f2();
2113
  int g(const int&);
 
2131
  a.p(); // calls A::p()&
2132
  ```
2133
 
2134
  — *end example*]
2135
  or, if not that,
2136
+ - `S1` and `S2` include reference bindings [[dcl.init.ref]] and `S1`
2137
  binds an lvalue reference to a function lvalue and `S2` binds an
2138
  rvalue reference to a function lvalue
2139
+ \[*Example 4*:
2140
  ``` cpp
2141
  int f(void(&)()); // #1
2142
  int f(void(&&)()); // #2
2143
  void g();
2144
  int i1 = f(g); // calls #1
2145
  ```
2146
 
2147
  — *end example*]
2148
  or, if not that,
2149
+ - `S1` and `S2` differ only in their qualification conversion
2150
+ [[conv.qual]] and yield similar types `T1` and `T2`, respectively,
2151
+ where `T1` can be converted to `T2` by a qualification conversion.
2152
+ \[*Example 5*:
 
 
2153
  ``` cpp
2154
  int f(const volatile int *);
2155
  int f(const int *);
2156
  int i;
2157
  int j = f(&i); // calls f(const int*)
2158
  ```
2159
 
2160
  — *end example*]
2161
  or, if not that,
2162
  - `S1`
2163
+ and `S2` include reference bindings [[dcl.init.ref]], and the types
2164
  to which the references refer are the same type except for top-level
2165
  cv-qualifiers, and the type to which the reference initialized by
2166
  `S2` refers is more cv-qualified than the type to which the
2167
  reference initialized by `S1` refers.
2168
+ \[*Example 6*:
2169
  ``` cpp
2170
  int f(const int &);
2171
  int f(int &);
2172
  int g(const int &);
2173
  int g(int);
 
2191
  than another user-defined conversion sequence `U2` if they contain the
2192
  same user-defined conversion function or constructor or they
2193
  initialize the same class in an aggregate initialization and in either
2194
  case the second standard conversion sequence of `U1` is better than
2195
  the second standard conversion sequence of `U2`.
2196
+ \[*Example 7*:
2197
  ``` cpp
2198
  struct A {
2199
  operator short();
2200
  } a;
2201
  int f(int);
 
2209
  Standard conversion sequences are ordered by their ranks: an Exact Match
2210
  is a better conversion than a Promotion, which is a better conversion
2211
  than a Conversion. Two conversion sequences with the same rank are
2212
  indistinguishable unless one of the following rules applies:
2213
 
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
 
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;
 
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.
2285
+ Otherwise, a non-template function with type `F` is selected for the
2286
+ 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
 
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
2317
+ function that is not a function template specialization. Any given
2318
+ non-template function `F0` is eliminated if the set contains a second
2319
+ non-template function that is more constrained than `F0` according to
2320
+ the partial ordering rules of [[temp.constr.order]]. Any given function
2321
+ template specialization `F1` is eliminated if the set contains a second
2322
+ function template specialization whose function template is more
2323
+ specialized than the function template of `F1` according to the partial
2324
+ ordering rules of  [[temp.func.order]]. After such eliminations, if any,
2325
+ there shall remain exactly one selected function.
2326
 
2327
  [*Example 1*:
2328
 
2329
  ``` cpp
2330
  int f(double);
 
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
  ```
2395
 
2396
+ ``` bnf
2397
+ %% Ed. note: character protrusion would misalign various operators.
2398
+ operator: one of
2399
+ 'new delete new[] delete[] co_await ( ) [ ] -> ->*'
2400
+ '~ ! + - * / % ^ &'
2401
+ '| = += -= *= /= %= ^= &='
2402
+ '|= == != < > <= >= <=> &&'
2403
+ '|| << >> <<= >>= ++ -- ,'
2404
+ ```
2405
+
2406
+ [*Note 1*: The operators `new[]`, `delete[]`, `()`, and `[]` are formed
2407
+ from more than one token. The latter two operators are function call
2408
+ [[expr.call]] and subscripting [[expr.sub]]. — *end note*]
2409
 
2410
  Both the unary and binary forms of
2411
 
2412
+ ``` bnf
2413
+ '+ - * &'
2414
  ```
2415
 
2416
  can be overloaded.
2417
 
2418
+ [*Note 2*:
2419
+
2420
  The following operators cannot be overloaded:
2421
 
2422
+ ``` bnf
2423
+ '. .* :: ?:'
2424
  ```
2425
 
2426
+ nor can the preprocessing symbols `#` [[cpp.stringize]] and `##`
2427
+ [[cpp.concat]].
2428
+
2429
+ — *end note*]
2430
 
2431
  Operator functions are usually not called directly; instead they are
2432
  invoked to evaluate the operators they implement ([[over.unary]] –
2433
  [[over.inc]]). They can be explicitly called, however, using the
2434
  *operator-function-id* as the name of the function in the function call
2435
+ syntax [[expr.call]].
2436
 
2437
  [*Example 1*:
2438
 
2439
  ``` cpp
2440
  complex z = a.operator+(b); // complex z = a+b;
 
2442
  ```
2443
 
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
2470
+ function.
 
2471
 
2472
+ [*Note 3*: The identities among certain predefined operators applied to
2473
+ basic types (for example, `++a` `a+=1`) need not hold for operator
2474
+ functions. Some predefined operators, such as `+=`, require an operand
2475
+ 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
+
2501
+ Otherwise, if a non-member function is selected, the expression is
2502
+ 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 ')'
2529
+ ```
2530
+
2531
+ Otherwise, if a non-member function is selected, the expression is
2532
+ interpreted as
2533
+
2534
+ ``` bnf
2535
+ operator '@' '(' x ',' y ')'
2536
+ ```
2537
+
2538
+ An *equality operator function* is an operator function for an equality
2539
+ operator [[expr.eq]]. A *relational operator function* is an operator
2540
+ function for a relational operator [[expr.rel]]. A
2541
+ *three-way comparison operator function* is an operator function for the
2542
+ three-way comparison operator [[expr.spaceship]]. A
2543
+ *comparison operator function* is an equality operator function, a
2544
+ relational operator function, or a three-way comparison operator
2545
+ function.
2546
+
2547
+ #### Simple assignment <a id="over.ass">[[over.ass]]</a>
2548
+
2549
+ A *simple assignment operator function* is a binary operator function
2550
+ named `operator=`. A simple assignment operator function shall be a
2551
+ non-static member function.
2552
+
2553
+ [*Note 1*: Because only standard conversion sequences are considered
2554
+ when converting to the left operand of an assignment operation
2555
+ [[over.best.ics]], an expression `x = y` with a subexpression x of class
2556
+ type is always interpreted as `x.operator=(y)`. — *end note*]
2557
+
2558
+ [*Note 2*: Since a copy assignment operator is implicitly declared for
2559
+ a class if not declared by the user [[class.copy.assign]], a base class
2560
+ assignment operator function is always hidden by the copy assignment
2561
+ operator function of the derived class. — *end note*]
2562
+
2563
+ [*Note 3*:
2564
+
2565
+ Any assignment operator function, even the copy and move assignment
2566
+ operators, can be virtual. For a derived class `D` with a base class `B`
2567
+ for which a virtual copy/move assignment has been declared, the
2568
+ copy/move assignment operator in `D` does not override `B`’s virtual
2569
+ copy/move assignment operator.
2570
 
2571
  [*Example 1*:
2572
 
2573
  ``` cpp
2574
  struct B {
 
2596
 
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 {
 
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
 
2666
+ the operator function is selected by overload resolution
2667
+ [[over.match.oper]], and the expression is interpreted as
2668
+
2669
+ ``` bnf
2670
+ '(' postfix-expression . operator '->' '('')' ')' '->' templateₒₚₜ id-expression
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
  }
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
2719
  candidate functions participate in the operator overload resolution
2720
  process as described in  [[over.match.oper]] and are used for no other
2721
  purpose.
2722
 
2723
  [*Note 1*: Because built-in operators take only operands with non-class
 
2729
  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
 
 
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
  ```
 
2822
 
2823
  where *cv12* is the union of *cv1* and *cv2*. The return type is shown
2824
  for exposition only; see  [[expr.mptr.oper]] for the determination of
2825
  the operator’s result type.
2826
 
2827
+ For every pair of types `L` and `R`, where each of `L` and `R` is a
2828
+ floating-point or promoted integral type, there exist candidate operator
2829
+ functions of the form
2830
 
2831
  ``` cpp
2832
  LR operator*(L, R);
2833
  LR operator/(L, R);
2834
  LR operator+(L, R);
2835
  LR operator-(L, R);
2836
+ bool operator==(L, R);
2837
+ bool operator!=(L, R);
2838
  bool operator<(L, R);
2839
  bool operator>(L, R);
2840
  bool operator<=(L, R);
2841
  bool operator>=(L, R);
 
 
2842
  ```
2843
 
2844
+ where `LR` is the result of the usual arithmetic conversions
2845
+ [[expr.arith.conv]] between types `L` and `R`.
2846
+
2847
+ For every integral type `T` there exists a candidate operator function
2848
+ of the form
2849
+
2850
+ ``` cpp
2851
+ std::strong_ordering operator<=>(T, T);
2852
+ ```
2853
+
2854
+ For every pair of floating-point types `L` and `R`, there exists a
2855
+ candidate operator function of the form
2856
+
2857
+ ``` cpp
2858
+ std::partial_ordering operator<=>(L, R);
2859
+ ```
2860
 
2861
  For every cv-qualified or cv-unqualified object type `T` there exist
2862
  candidate operator functions of the form
2863
 
2864
  ``` cpp
 
2878
 
2879
  For every `T`, where `T` is an enumeration type or a pointer type, there
2880
  exist candidate operator functions of the form
2881
 
2882
  ``` cpp
2883
+ bool operator==(T, T);
2884
+ bool operator!=(T, T);
2885
  bool operator<(T, T);
2886
  bool operator>(T, T);
2887
  bool operator<=(T, T);
2888
  bool operator>=(T, T);
2889
+ R operator<=>(T, T);
 
2890
  ```
2891
 
2892
+ where `R` is the result type specified in [[expr.spaceship]].
2893
+
2894
+ For every `T`, where `T` is a pointer-to-member type or
2895
+ `std::nullptr_t`, there exist candidate operator functions of the form
2896
 
2897
  ``` cpp
2898
  bool operator==(T, T);
2899
  bool operator!=(T, T);
2900
  ```
 
2909
  LR operator|(L, R);
2910
  L operator<<(L, R);
2911
  L operator>>(L, R);
2912
  ```
2913
 
2914
+ where `LR` is the result of the usual arithmetic conversions
2915
+ [[expr.arith.conv]] between types `L` and `R`.
2916
 
2917
  For every triple (`L`, *vq*, `R`), where `L` is an arithmetic type, and
2918
+ `R` is a floating-point or promoted integral type, there exist candidate
2919
+ operator functions of the form
2920
 
2921
  ``` cpp
2922
  vq L& operator=(vq L&, R);
2923
  vq L& operator*=(vq L&, R);
2924
  vq L& operator/=(vq L&, R);
 
2931
 
2932
  ``` cpp
2933
  T*vq& operator=(T*vq&, T*);
2934
  ```
2935
 
2936
+ For every pair (`T`, *vq*), where `T` is an enumeration or
2937
+ pointer-to-member type, there exist candidate operator functions of the
2938
+ form
2939
 
2940
  ``` cpp
2941
  vq T& operator=(vq T&, T);
2942
  ```
2943
 
 
2969
  bool operator!(bool);
2970
  bool operator&&(bool, bool);
2971
  bool operator||(bool, bool);
2972
  ```
2973
 
2974
+ For every pair of types `L` and `R`, where each of `L` and `R` is a
2975
+ floating-point or promoted integral type, there exist candidate operator
2976
+ functions of the form
2977
 
2978
  ``` cpp
2979
  LR operator?:(bool, L, R);
2980
  ```
2981
 
2982
+ where `LR` is the result of the usual arithmetic conversions
2983
+ [[expr.arith.conv]] between types `L` and `R`.
2984
 
2985
  [*Note 3*: As with all these descriptions of candidate functions, this
2986
  declaration serves only to describe the built-in operator for purposes
2987
  of overload resolution. The operator “`?:`” cannot be
2988
  overloaded. — *end note*]
 
2992
 
2993
  ``` cpp
2994
  T operator?:(bool, T, T);
2995
  ```
2996
 
2997
+ ## User-defined literals <a id="over.literal">[[over.literal]]</a>
2998
+
2999
+ ``` bnf
3000
+ literal-operator-id:
3001
+ operator string-literal identifier
3002
+ operator user-defined-string-literal
3003
+ ```
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
3026
+ const char*
3027
+ unsigned long long int
3028
+ long double
3029
+ char
3030
+ wchar_t
3031
+ char8_t
3032
+ char16_t
3033
+ char32_t
3034
+ const char*, std::size_t
3035
+ const wchar_t*, std::size_t
3036
+ const char8_t*, std::size_t
3037
+ const char16_t*, std::size_t
3038
+ const char32_t*, std::size_t
3039
+ ```
3040
+
3041
+ If a parameter has a default argument [[dcl.fct.default]], the program
3042
+ is ill-formed.
3043
+
3044
+ A *raw literal operator* is a literal operator with a single parameter
3045
+ whose type is `const char*`.
3046
+
3047
+ A *numeric literal operator template* is a literal operator template
3048
+ whose *template-parameter-list* has a single *template-parameter* that
3049
+ is a non-type template parameter pack [[temp.variadic]] with element
3050
+ type `char`. A *string literal operator template* is a literal operator
3051
+ template whose *template-parameter-list* comprises a single non-type
3052
+ *template-parameter* of class type. The declaration of a literal
3053
+ operator template shall have an empty *parameter-declaration-clause* and
3054
+ shall declare either a numeric literal operator template or a string
3055
+ literal operator template.
3056
+
3057
+ Literal operators and literal operator templates shall not have C
3058
+ language linkage.
3059
+
3060
+ [*Note 1*: Literal operators and literal operator templates are usually
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
3085
+ ```
3086
+
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
3111
+ [conv.fpint]: expr.md#conv.fpint
3112
+ [conv.fpprom]: expr.md#conv.fpprom
3113
+ [conv.func]: expr.md#conv.func
3114
+ [conv.integral]: expr.md#conv.integral
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
3129
  [dcl.init.aggr]: dcl.md#dcl.init.aggr
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
3142
+ [expr.compound]: expr.md#expr.compound
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
3153
  [expr.unary.op]: expr.md#expr.unary.op
3154
  [lex.ext]: lex.md#lex.ext
 
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
3192
  [stmt.return]: stmt.md#stmt.return
 
 
3193
  [temp.arg.explicit]: temp.md#temp.arg.explicit
3194
  [temp.arg.nontype]: temp.md#temp.arg.nontype
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`
 
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
 
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`.