From Jason Turner

[over.match]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpaxppttzr/{from.md → to.md} +745 -352
tmp/tmpaxppttzr/{from.md → to.md} RENAMED
@@ -15,73 +15,73 @@ as the accessibility of the function, can make its use in the calling
15
  context ill-formed. — *end note*]
16
 
17
  Overload resolution selects the function to call in seven distinct
18
  contexts within the language:
19
 
20
- - invocation of a function named in the function call syntax (
21
- [[over.call.func]]);
22
  - invocation of a function call operator, a pointer-to-function
23
  conversion function, a reference-to-pointer-to-function conversion
24
  function, or a reference-to-function conversion function on a class
25
- object named in the function call syntax ([[over.call.object]]);
26
- - invocation of the operator referenced in an expression (
27
- [[over.match.oper]]);
28
- - invocation of a constructor for default- or direct-initialization (
29
- [[dcl.init]]) of a class object ([[over.match.ctor]]);
30
- - invocation of a user-defined conversion for copy-initialization (
31
- [[dcl.init]]) of a class object ([[over.match.copy]]);
32
  - invocation of a conversion function for initialization of an object of
33
- a non-class type from an expression of class type (
34
- [[over.match.conv]]); and
35
- - invocation of a conversion function for conversion to a glvalue or
36
- class prvalue to which a reference ([[dcl.init.ref]]) will be
37
- directly bound ([[over.match.ref]]).
38
 
39
  Each of these contexts defines the set of candidate functions and the
40
  list of arguments in its own unique way. But, once the candidate
41
  functions and argument lists have been identified, the selection of the
42
  best function is the same in all cases:
43
 
44
  - First, a subset of the candidate functions (those that have the proper
45
  number of arguments and meet certain other conditions) is selected to
46
- form a set of viable functions ([[over.match.viable]]).
47
  - Then the best viable function is selected based on the implicit
48
- conversion sequences ([[over.best.ics]]) needed to match each
49
- argument to the corresponding parameter of each viable function.
50
 
51
  If a best viable function exists and is unique, overload resolution
52
  succeeds and produces it as the result. Otherwise overload resolution
53
  fails and the invocation is ill-formed. When overload resolution
54
- succeeds, and the best viable function is not accessible (Clause 
55
- [[class.access]]) in the context in which it is used, the program is
56
  ill-formed.
57
 
 
 
 
 
 
58
  ### Candidate functions and argument lists <a id="over.match.funcs">[[over.match.funcs]]</a>
59
 
60
  The subclauses of  [[over.match.funcs]] describe the set of candidate
61
  functions and the argument list submitted to overload resolution in each
62
- of the seven contexts in which overload resolution is used. The source
63
- transformations and constructions defined in these subclauses are only
64
- for the purpose of describing the overload resolution process. An
65
- implementation is not required to use such transformations and
66
- constructions.
67
 
68
  The set of candidate functions can contain both member and non-member
69
  functions to be resolved against the same argument list. So that
70
  argument and parameter lists are comparable within this heterogeneous
71
- set, a member function is considered to have an extra parameter, called
72
- the *implicit object parameter*, which represents the object for which
73
- the member function has been called. For the purposes of overload
74
  resolution, both static and non-static member functions have an implicit
75
  object parameter, but constructors do not.
76
 
77
  Similarly, when appropriate, the context can construct an argument list
78
- that contains an *implied object argument* to denote the object to be
79
- operated on. Since arguments and parameters are associated by position
80
- within their respective lists, the convention is that the implicit
81
- object parameter, if present, is always the first parameter and the
82
- implied object argument, if present, is always the first argument.
83
 
84
  For non-static member functions, the type of the implicit object
85
  parameter is
86
 
87
  - “lvalue reference to cv `X`” for functions declared without a
@@ -105,25 +105,25 @@ defining the type of the implicit object parameter. For static member
105
  functions, the implicit object parameter is considered to match any
106
  object (since if the function is selected, the object is discarded).
107
 
108
  [*Note 1*: No actual type is established for the implicit object
109
  parameter of a static member function, and no attempt will be made to
110
- determine a conversion sequence for that parameter (
111
- [[over.match.best]]). — *end note*]
112
 
113
  During overload resolution, the implied object argument is
114
  indistinguishable from other arguments. The implicit object parameter,
115
  however, retains its identity since no user-defined conversions can be
116
  applied to achieve a type match with it. For non-static member functions
117
- declared without a *ref-qualifier*, an additional rule applies:
 
 
 
118
 
119
- - even if the implicit object parameter is not const-qualified, an
120
- rvalue can be bound to the parameter as long as in all other respects
121
- the argument can be converted to the type of the implicit object
122
- parameter. \[*Note 2*: The fact that such an argument is an rvalue
123
- does not affect the ranking of implicit conversion sequences (
124
- [[over.ics.rank]]). — *end note*]
125
 
126
  Because other than in list-initialization only one user-defined
127
  conversion is allowed in an implicit conversion sequence, special rules
128
  apply when selecting the best user-defined conversion (
129
  [[over.match.best]], [[over.best.ics]]).
@@ -138,46 +138,80 @@ public:
138
 
139
  class C : T {
140
  public:
141
  C(int);
142
  };
143
- T a = 1; // ill-formed: T(C(1)) not tried
144
  ```
145
 
146
  — *end example*]
147
 
148
  In each case where a candidate is a function template, candidate
149
  function template specializations are generated using template argument
150
- deduction ([[temp.over]], [[temp.deduct]]). Those candidates are then
151
- handled as candidate functions in the usual way.[^2] A given name can
152
- refer to one or more function templates and also to a set of overloaded
153
- non-template functions. In such a case, the candidate functions
154
- generated from each function template are combined with the set of
155
- non-template candidate functions.
156
-
157
- A defaulted move constructor or assignment operator ([[class.copy]])
158
- that is defined as deleted is excluded from the set of candidate
159
- functions in all contexts.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
  #### Function call syntax <a id="over.match.call">[[over.match.call]]</a>
162
 
163
- In a function call ([[expr.call]])
164
 
165
  ``` bnf
166
  postfix-expression '(' expression-listₒₚₜ ')'
167
  ```
168
 
169
- if the *postfix-expression* denotes a set of overloaded functions and/or
170
- function templates, overload resolution is applied as specified in
171
  [[over.call.func]]. If the *postfix-expression* denotes an object of
172
  class type, overload resolution is applied as specified in
173
  [[over.call.object]].
174
 
175
- If the *postfix-expression* denotes the address of a set of overloaded
176
- functions and/or function templates, overload resolution is applied
177
- using that set as described above. If the function selected by overload
178
- resolution is a non-static member function, the program is ill-formed.
179
 
180
  [*Note 1*: The resolution of the address of an overload set in other
181
  contexts is described in [[over.over]]. — *end note*]
182
 
183
  ##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
@@ -199,82 +233,75 @@ These represent two syntactic subcategories of function calls: qualified
199
  function calls and unqualified function calls.
200
 
201
  In qualified function calls, the name to be resolved is an
202
  *id-expression* and is preceded by an `->` or `.` operator. Since the
203
  construct `A->B` is generally equivalent to `(*A).B`, the rest of
204
- Clause  [[over]] assumes, without loss of generality, that all member
205
- function calls have been normalized to the form that uses an object and
206
- the `.` operator. Furthermore, Clause  [[over]] assumes that the
207
- *postfix-expression* that is the left operand of the `.` operator has
208
- type “cv `T`” where `T` denotes a class[^3]. Under this assumption, the
209
- *id-expression* in the call is looked up as a member function of `T`
210
- following the rules for looking up names in classes (
211
- [[class.member.lookup]]). The function declarations found by that lookup
212
- constitute the set of candidate functions. The argument list is the
213
- *expression-list* in the call augmented by the addition of the left
214
- operand of the `.` operator in the normalized member function call as
215
- the implied object argument ([[over.match.funcs]]).
216
 
217
  In unqualified function calls, the name is not qualified by an `->` or
218
  `.` operator and has the more general form of a *primary-expression*.
219
  The name is looked up in the context of the function call following the
220
- normal rules for name lookup in function calls ([[basic.lookup]]). The
221
  function declarations found by that lookup constitute the set of
222
  candidate functions. Because of the rules for name lookup, the set of
223
  candidate functions consists (1) entirely of non-member functions or (2)
224
  entirely of member functions of some class `T`. In case (1), the
225
  argument list is the same as the *expression-list* in the call. In case
226
  (2), the argument list is the *expression-list* in the call augmented by
227
  the addition of an implied object argument as in a qualified function
228
- call. If the keyword `this` ([[class.this]]) is in scope and refers to
229
  class `T`, or a derived class of `T`, then the implied object argument
230
  is `(*this)`. If the keyword `this` is not in scope or refers to another
231
  class, then a contrived object of type `T` becomes the implied object
232
- argument[^4]. If the argument list is augmented by a contrived object
233
  and overload resolution selects one of the non-static member functions
234
  of `T`, the call is ill-formed.
235
 
236
  ##### Call to object of class type <a id="over.call.object">[[over.call.object]]</a>
237
 
238
- If the *primary-expression* `E` in the function call syntax evaluates to
239
  a class object of type “cv `T`”, then the set of candidate functions
240
  includes at least the function call operators of `T`. The function call
241
  operators of `T` are obtained by ordinary lookup of the name
242
  `operator()` in the context of `(E).operator()`.
243
 
244
  In addition, for each non-explicit conversion function declared in `T`
245
  of the form
246
 
247
  ``` bnf
248
- 'operator' conversion-type-id '( )' cv-qualifier ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ ';'
249
  ```
250
 
251
- where *cv-qualifier* is the same cv-qualification as, or a greater
252
- cv-qualification than, cv, and where *conversion-type-id* denotes the
253
- type “pointer to function of (`P₁`, …, `Pₙ`) returning `R`”, or the type
254
- “reference to pointer to function of (`P₁`, …, `Pₙ`) returning `R`”, or
255
- the type “reference to function of (`P₁`, …, `Pₙ`) returning `R`”, a
256
- *surrogate call function* with the unique name *call-function* and
257
- having the form
258
 
259
  ``` bnf
260
- 'R' call-function '(' conversion-type-id \ %
261
  'F, P₁ a₁, …, Pₙ aₙ)' '{ return F (a₁, …, aₙ); }'
262
  ```
263
 
264
  is also considered as a candidate function. Similarly, surrogate call
265
  functions are added to the set of candidate functions for each
266
  non-explicit conversion function declared in a base class of `T`
267
  provided the function is not hidden within `T` by another intervening
268
- declaration[^5].
269
-
270
- If such a surrogate call function is selected by overload resolution,
271
- the corresponding conversion function will be called to convert `E` to
272
- the appropriate function pointer or reference, and the function will
273
- then be invoked with the arguments of the call. If the conversion
274
- function cannot be called (e.g., because of an ambiguity), the program
275
- is ill-formed.
276
 
277
  The argument list submitted to overload resolution consists of the
278
  argument expressions present in the function call syntax preceded by the
279
  implied object argument `(E)`.
280
 
@@ -306,18 +333,18 @@ int i = a(1); // calls f1 via pointer returned from conversion
306
 
307
  #### Operators in expressions <a id="over.match.oper">[[over.match.oper]]</a>
308
 
309
  If no operand of an operator in an expression has a type that is a class
310
  or an enumeration, the operator is assumed to be a built-in operator and
311
- interpreted according to Clause  [[expr]].
312
 
313
  [*Note 1*: Because `.`, `.*`, and `::` cannot be overloaded, these
314
- operators are always built-in operators interpreted according to Clause 
315
- [[expr]]. `?:` cannot be overloaded, but the rules in this subclause are
316
- used to determine the conversions to be applied to the second and third
317
- operands when they have class or enumeration type (
318
- [[expr.cond]]). — *end note*]
319
 
320
  [*Example 1*:
321
 
322
  ``` cpp
323
  struct String {
@@ -326,11 +353,12 @@ struct String {
326
  operator const char* ();
327
  };
328
  String operator + (const String&, const String&);
329
 
330
  void f() {
331
- const char* p= "one" + "two"; // ill-formed because neither operand has class or enumeration type
 
332
  int I = 1 + 1; // always evaluates to 2 even if class or enumeration types exist
333
  // that would perform the operation.
334
  }
335
  ```
336
 
@@ -341,16 +369,16 @@ user-defined operator function might be declared that implements this
341
  operator or a user-defined conversion can be necessary to convert the
342
  operand to a type that is appropriate for a built-in operator. In this
343
  case, overload resolution is used to determine which operator function
344
  or built-in operator is to be invoked to implement the operator.
345
  Therefore, the operator notation is first transformed to the equivalent
346
- function-call notation as summarized in Table  [[tab:over.rel.op.func]]
347
- (where `@` denotes one of the operators covered in the specified
348
- subclause). However, the operands are sequenced in the order prescribed
349
- for the built-in operator (Clause  [[expr]]).
350
 
351
- **Table: Relationship between operator and function call notation** <a id="tab:over.rel.op.func">[tab:over.rel.op.func]</a>
352
 
353
  | Subclause | Expression | As member function | As non-member function |
354
  | ------------ | ---------- | ------------------- | ---------------------- |
355
  | (a)} |
356
  | (a, b)} |
@@ -358,25 +386,24 @@ for the built-in operator (Clause  [[expr]]).
358
  | [[over.sub]] | `a[b]` | `(a).operator[](b)` | |
359
  | [[over.ref]] | `a->` | `(a).operator->( )` | |
360
  | (a, 0)} |
361
 
362
 
363
- For a unary operator `@` with an operand of a type whose cv-unqualified
364
- version is `T1`, and for a binary operator `@` with a left operand of a
365
- type whose cv-unqualified version is `T1` and a right operand of a type
366
- whose cv-unqualified version is `T2`, three sets of candidate functions,
367
- designated *member candidates*, *non-member candidates* and *built-in
368
- candidates*, are constructed as follows:
369
 
370
  - If `T1` is a complete class type or a class currently being defined,
371
  the set of member candidates is the result of the qualified lookup of
372
- `T1::operator@` ([[over.call.func]]); otherwise, the set of member
373
  candidates is empty.
374
  - The set of non-member candidates is the result of the unqualified
375
  lookup of `operator@` in the context of the expression according to
376
- the usual rules for name lookup in unqualified function calls (
377
- [[basic.lookup.argdep]]) except that all member functions are ignored.
378
  However, if no operand has a class type, only those non-member
379
  functions in the lookup set that have a first parameter of type `T1`
380
  or “reference to cv `T1`”, when `T1` is an enumeration type, or (if
381
  there is a right operand) a second parameter of type `T2` or
382
  “reference to cv `T2`”, when `T2` is an enumeration type, are
@@ -389,26 +416,48 @@ candidates*, are constructed as follows:
389
  - accept the same number of operands, and
390
  - accept operand types to which the given operand or operands can be
391
  converted according to [[over.best.ics]], and
392
  - do not have the same parameter-type-list as any non-member candidate
393
  that is not a function template specialization.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
 
395
  For the built-in assignment operators, conversions of the left operand
396
  are restricted as follows:
397
 
398
  - no temporaries are introduced to hold the left operand, and
399
  - no user-defined conversions are applied to the left operand to achieve
400
  a type match with the left-most parameter of a built-in candidate.
401
 
402
  For all other operators, no such restrictions apply.
403
 
404
- The set of candidate functions for overload resolution is the union of
405
- the member candidates, the non-member candidates, and the built-in
406
- candidates. The argument list contains all of the operands of the
407
- operator. The best function from the set of candidate functions is
408
- selected according to  [[over.match.viable]] and 
409
- [[over.match.best]].[^6]
 
 
410
 
411
  [*Example 2*:
412
 
413
  ``` cpp
414
  struct A {
@@ -421,17 +470,36 @@ void m() {
421
  }
422
  ```
423
 
424
  — *end example*]
425
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  If a built-in candidate is selected by overload resolution, the operands
427
  of class type are converted to the types of the corresponding parameters
428
  of the selected operation function, except that the second standard
429
- conversion sequence of a user-defined conversion sequence (
430
- [[over.ics.user]]) is not applied. Then the operator is treated as the
431
- corresponding built-in operator and interpreted according to Clause 
432
- [[expr]].
433
 
434
  [*Example 3*:
435
 
436
  ``` cpp
437
  struct X {
@@ -453,14 +521,14 @@ The second operand of operator `->` is ignored in selecting an
453
  function is called. When `operator->` returns, the operator `->` is
454
  applied to the value returned, with the original second operand.[^7]
455
 
456
  If the operator is the operator `,`, the unary operator `&`, or the
457
  operator `->`, and there are no viable functions, then the operator is
458
- assumed to be the built-in operator and interpreted according to Clause 
459
- [[expr]].
460
 
461
- [*Note 2*:
462
 
463
  The lookup rules for operators in expressions are different than the
464
  lookup rules for operator function names in a function call, as shown in
465
  the following example:
466
 
@@ -483,19 +551,20 @@ void B::f() {
483
 
484
  — *end note*]
485
 
486
  #### Initialization by constructor <a id="over.match.ctor">[[over.match.ctor]]</a>
487
 
488
- When objects of class type are direct-initialized ([[dcl.init]]),
489
- copy-initialized from an expression of the same or a derived class
490
- type ([[dcl.init]]), or default-initialized ([[dcl.init]]), overload
491
- resolution selects the constructor. For direct-initialization or
492
  default-initialization that is not in the context of
493
  copy-initialization, the candidate functions are all the constructors of
494
- the class of the object being initialized. For copy-initialization, the
495
- candidate functions are all the converting constructors (
496
- [[class.conv.ctor]]) of that class. The argument list is the
 
497
  *expression-list* or *assignment-expression* of the *initializer*.
498
 
499
  #### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
500
 
501
  Under the conditions specified in  [[dcl.init]], as part of a
@@ -509,25 +578,25 @@ to a possibly cv-qualified class type is determined in terms of a
509
  corresponding non-reference copy-initialization. — *end note*]
510
 
511
  Assuming that “*cv1* `T`” is the type of the object being initialized,
512
  with `T` a class type, the candidate functions are selected as follows:
513
 
514
- - The converting constructors ([[class.conv.ctor]]) of `T` are
515
- candidate functions.
516
  - When the type of the initializer expression is a class type “cv `S`”,
517
  the non-explicit conversion functions of `S` and its base classes are
518
- considered. When initializing a temporary to be bound to the first
519
- parameter of a constructor where the parameter is of type “reference
520
- to possibly cv-qualified `T`” and the constructor is called with a
521
  single argument in the context of direct-initialization of an object
522
- of type “*cv2* `T`”, explicit conversion functions are also
523
  considered. Those that are not hidden within `S` and yield a type
524
  whose cv-unqualified version is the same type as `T` or is a derived
525
- class thereof are candidate functions. Conversion functions that
526
- return “reference to `X`” return lvalues or xvalues, depending on the
527
- type of reference, of type `X` and are therefore considered to yield
528
- `X` for this process of selecting candidate functions.
529
 
530
  In both cases, the argument list has one argument, which is the
531
  initializer expression.
532
 
533
  [*Note 2*: This argument will be compared against the first parameter
@@ -546,120 +615,226 @@ the initializer expression, with `S` a class type, the candidate
546
  functions are selected as follows:
547
 
548
  - The conversion functions of `S` and its base classes are considered.
549
  Those non-explicit conversion functions that are not hidden within `S`
550
  and yield type `T` or a type that can be converted to type `T` via a
551
- standard conversion sequence ([[over.ics.scs]]) are candidate
552
- functions. For direct-initialization, those explicit conversion
553
- functions that are not hidden within `S` and yield type `T` or a type
554
- that can be converted to type `T` with a qualification conversion (
555
- [[conv.qual]]) are also candidate functions. Conversion functions that
556
- return a cv-qualified type are considered to yield the cv-unqualified
557
- version of that type for this process of selecting candidate
558
- functions. Conversion functions that return “reference to *cv2* `X`”
559
- return lvalues or xvalues, depending on the type of reference, of type
560
- “*cv2* `X`” and are therefore considered to yield `X` for this process
561
- of selecting candidate functions.
562
 
563
  The argument list has one argument, which is the initializer expression.
564
 
565
  [*Note 1*: This argument will be compared against the implicit object
566
  parameter of the conversion functions. — *end note*]
567
 
568
  #### Initialization by conversion function for direct reference binding <a id="over.match.ref">[[over.match.ref]]</a>
569
 
570
  Under the conditions specified in  [[dcl.init.ref]], a reference can be
571
- bound directly to a glvalue or class prvalue that is the result of
572
- applying a conversion function to an initializer expression. Overload
573
- resolution is used to select the conversion function to be invoked.
574
- Assuming that “reference to *cv1* `T`” is the type of the reference
575
- being initialized, and “cv `S` is the type of the initializer
576
- expression, with `S` a class type, the candidate functions are selected
577
- as follows:
578
 
579
  - The conversion functions of `S` and its base classes are considered.
580
  Those non-explicit conversion functions that are not hidden within `S`
581
  and yield type “lvalue reference to *cv2* `T2`” (when initializing an
582
  lvalue reference or an rvalue reference to function) or “*cv2* `T2`”
583
  or “rvalue reference to *cv2* `T2`” (when initializing an rvalue
584
  reference or an lvalue reference to function), where “*cv1* `T`” is
585
- reference-compatible ([[dcl.init.ref]]) with “*cv2* `T2`”, are
586
- candidate functions. For direct-initialization, those explicit
587
- conversion functions that are not hidden within `S` and yield type
588
- “lvalue reference to *cv2* `T2`” or “*cv2* `T2`” or “rvalue reference
589
- to *cv2* `T2`”, respectively, where `T2` is the same type as `T` or
590
- can be converted to type `T` with a qualification conversion (
591
- [[conv.qual]]), are also candidate functions.
 
 
592
 
593
  The argument list has one argument, which is the initializer expression.
594
 
595
  [*Note 1*: This argument will be compared against the implicit object
596
  parameter of the conversion functions. — *end note*]
597
 
598
  #### Initialization by list-initialization <a id="over.match.list">[[over.match.list]]</a>
599
 
600
  When objects of non-aggregate class type `T` are list-initialized such
601
  that [[dcl.init.list]] specifies that overload resolution is performed
602
- according to the rules in this section, overload resolution selects the
603
- constructor in two phases:
 
604
 
605
- - Initially, the candidate functions are the initializer-list
606
- constructors ([[dcl.init.list]]) of the class `T` and the argument
607
- list consists of the initializer list as a single argument.
608
- - If no viable initializer-list constructor is found, overload
609
- resolution is performed again, where the candidate functions are all
610
- the constructors of the class `T` and the argument list consists of
611
- the elements of the initializer list.
 
 
612
 
613
- If the initializer list has no elements and `T` has a default
614
- constructor, the first phase is omitted. In copy-list-initialization, if
615
- an `explicit` constructor is chosen, the initialization is ill-formed.
616
 
617
- [*Note 1*: This differs from other situations ([[over.match.ctor]], 
618
  [[over.match.copy]]), where only converting constructors are considered
619
  for copy-initialization. This restriction only applies if this
620
  initialization is part of the final result of overload
621
  resolution. — *end note*]
622
 
623
  #### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
624
 
625
- A set of functions and function templates is formed comprising:
 
 
 
626
 
627
- - For each constructor of the primary class template designated by the
628
- *template-name*, if the template is defined, a function template with
629
- the following properties:
630
- - The template parameters are the template parameters of the class
631
- template followed by the template parameters (including default
632
- template arguments) of the constructor, if any.
633
  - The types of the function parameters are those of the constructor.
634
  - The return type is the class template specialization designated by
635
- the *template-name* and template arguments corresponding to the
636
- template parameters obtained from the class template.
637
- - If the primary class template `C` is not defined or does not declare
638
- any constructors, an additional function template derived as above
639
- from a hypothetical constructor `C()`.
640
  - An additional function template derived as above from a hypothetical
641
  constructor `C(C)`, called the *copy deduction candidate*.
642
  - For each *deduction-guide*, a function or function template with the
643
  following properties:
644
  - The template parameters, if any, and function parameters are those
645
  of the *deduction-guide*.
646
  - The return type is the *simple-template-id* of the
647
  *deduction-guide*.
648
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
649
  Initialization and overload resolution are performed as described in
650
  [[dcl.init]] and [[over.match.ctor]], [[over.match.copy]], or
651
  [[over.match.list]] (as appropriate for the type of initialization
652
- performed) for an object of a hypothetical class type, where the
653
- selected functions and function templates are considered to be the
654
  constructors of that class type for the purpose of forming an overload
655
  set, and the initializer is provided by the context in which class
656
- template argument deduction was performed. Each such notional
657
- constructor is considered to be explicit if the function or function
658
- template was generated from a constructor or *deduction-guide* that was
659
- declared `explicit`. All such notional constructors are considered to be
660
- public members of the hypothetical class type.
 
 
 
 
 
 
 
 
 
 
 
 
 
661
 
662
  [*Example 1*:
663
 
664
  ``` cpp
665
  template <class T> struct A {
@@ -687,44 +862,163 @@ template <class T> struct B {
687
  template <class U> using TA = T;
688
  template <class U> B(U, TA<U>);
689
  };
690
 
691
  B b{(int*)0, (char*)0}; // OK, deduces B<char*>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
692
  ```
693
 
694
  — *end example*]
695
 
696
  ### Viable functions <a id="over.match.viable">[[over.match.viable]]</a>
697
 
698
- From the set of candidate functions constructed for a given context (
699
- [[over.match.funcs]]), a set of viable functions is chosen, from which
700
  the best function will be selected by comparing argument conversion
701
- sequences for the best fit ([[over.match.best]]). The selection of
702
- viable functions considers relationships between arguments and function
703
- parameters other than the ranking of conversion sequences.
 
704
 
705
  First, to be a viable function, a candidate function shall have enough
706
  parameters to agree in number with the arguments in the list.
707
 
708
  - If there are *m* arguments in the list, all candidate functions having
709
  exactly *m* parameters are viable.
710
  - A candidate function having fewer than *m* parameters is viable only
711
- if it has an ellipsis in its parameter list ([[dcl.fct]]). For the
712
  purposes of overload resolution, any argument for which there is no
713
- corresponding parameter is considered to “match the ellipsis” (
714
- [[over.ics.ellipsis]]) .
715
  - A candidate function having more than *m* parameters is viable only if
716
- the *(m+1)*-st parameter has a default argument (
717
- [[dcl.fct.default]]).[^8] For the purposes of overload resolution, the
718
  parameter list is truncated on the right, so that there are exactly
719
  *m* parameters.
720
 
721
- Second, for `F` to be a viable function, there shall exist for each
722
- argument an *implicit conversion sequence* ([[over.best.ics]]) that
723
- converts that argument to the corresponding parameter of `F`. If the
724
- parameter has reference type, the implicit conversion sequence includes
725
- the operation of binding the reference, and the fact that an lvalue
 
 
 
 
726
  reference to non-`const` cannot be bound to an rvalue and that an rvalue
727
  reference cannot be bound to an lvalue can affect the viability of the
728
  function (see  [[over.ics.ref]]).
729
 
730
  ### Best viable function <a id="over.match.best">[[over.match.best]]</a>
@@ -732,11 +1026,11 @@ function (see  [[over.ics.ref]]).
732
  Define ICS*i*(`F`) as follows:
733
 
734
  - If `F` is a static member function, ICS*1*(`F`) is defined such that
735
  ICS*1*(`F`) is neither better nor worse than ICS*1*(`G`) for any
736
  function `G`, and, symmetrically, ICS*1*(`G`) is neither better nor
737
- worse than ICS*1*(`F`);[^9] otherwise,
738
  - let ICS*i*(`F`) denote the implicit conversion sequence that converts
739
  the *i*-th argument in the list to the type of the *i*-th parameter of
740
  viable function `F`. [[over.best.ics]] defines the implicit conversion
741
  sequences and [[over.ics.rank]] defines what it means for one implicit
742
  conversion sequence to be a better conversion sequence or worse
@@ -769,14 +1063,14 @@ and then
769
  ```
770
 
771
  — *end example*]
772
  or, if not that,
773
  - the context is an initialization by conversion function for direct
774
- reference binding ([[over.match.ref]]) of a reference to function
775
- type, the return type of `F1` is the same kind of reference (i.e.
776
- lvalue or rvalue) as the reference being initialized, and the return
777
- type of `F2` is not
778
  \[*Example 2*:
779
  ``` cpp
780
  template <class T> struct A {
781
  operator T&(); // #1
782
  operator T&&(); // #2
@@ -793,17 +1087,67 @@ and then
793
  template specialization, or, if not that,
794
  - `F1` and `F2` are function template specializations, and the function
795
  template for `F1` is more specialized than the template for `F2`
796
  according to the partial ordering rules described in 
797
  [[temp.func.order]], or, if not that,
798
- - `F1` is generated from a *deduction-guide* (
799
- [[over.match.class.deduct]]) and `F2` is not, or, if not that,
800
- - `F1` is the copy deduction candidate ([[over.match.class.deduct]])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
801
  and `F2` is not, or, if not that,
 
 
802
  - `F1` is generated from a non-template constructor and `F2` is
803
  generated from a constructor template.
804
- \[*Example 3*:
805
  ``` cpp
806
  template <class T> struct A {
807
  using value_type = T;
808
  A(value_type); // #1
809
  A(const A&); // #2
@@ -829,13 +1173,13 @@ and then
829
 
830
  — *end example*]
831
 
832
  If there is exactly one viable function that is a better function than
833
  all other viable functions, then it is the one selected by overload
834
- resolution; otherwise the call is ill-formed.[^10]
835
 
836
- [*Example 4*:
837
 
838
  ``` cpp
839
  void Fcn(const int*, short);
840
  void Fcn(int*, int);
841
 
@@ -860,11 +1204,11 @@ If the best viable function resolves to a function for which multiple
860
  declarations were found, and if at least two of these declarations — or
861
  the declarations they refer to in the case of *using-declaration*s —
862
  specify a default argument that made the function viable, the program is
863
  ill-formed.
864
 
865
- [*Example 5*:
866
 
867
  ``` cpp
868
  namespace A {
869
  extern "C" void f(int = 5);
870
  }
@@ -875,41 +1219,43 @@ namespace B {
875
  using A::f;
876
  using B::f;
877
 
878
  void use() {
879
  f(3); // OK, default argument was not used for viability
880
- f(); // Error: found default argument twice
881
  }
882
  ```
883
 
884
  — *end example*]
885
 
886
  #### Implicit conversion sequences <a id="over.best.ics">[[over.best.ics]]</a>
887
 
888
  An *implicit conversion sequence* is a sequence of conversions used to
889
  convert an argument in a function call to the type of the corresponding
890
  parameter of the function being called. The sequence of conversions is
891
- an implicit conversion as defined in Clause  [[conv]], which means it is
892
  governed by the rules for initialization of an object or reference by a
893
  single expression ([[dcl.init]], [[dcl.init.ref]]).
894
 
895
  Implicit conversion sequences are concerned only with the type,
896
  cv-qualification, and value category of the argument and how these are
897
- converted to match the corresponding properties of the parameter. Other
898
- properties, such as the lifetime, storage class, alignment,
899
- accessibility of the argument, whether the argument is a bit-field, and
900
- whether a function is deleted ([[dcl.fct.def.delete]]), are ignored.
901
- So, although an implicit conversion sequence can be defined for a given
902
- argument-parameter pair, the conversion from the argument to the
903
- parameter might still be ill-formed in the final analysis.
 
 
904
 
905
  A well-formed implicit conversion sequence is one of the following
906
  forms:
907
 
908
- - a *standard conversion sequence* ([[over.ics.scs]]),
909
- - a *user-defined conversion sequence* ([[over.ics.user]]), or
910
- - an *ellipsis conversion sequence* ([[over.ics.ellipsis]]).
911
 
912
  However, if the target is
913
 
914
  - the first parameter of a constructor or
915
  - the implicit object parameter of a user-defined conversion function
@@ -926,25 +1272,25 @@ by
926
  is the first parameter of a constructor of class `X`, and the
927
  conversion is to `X` or reference to cv `X`,
928
 
929
  user-defined conversion sequences are not considered.
930
 
931
- [*Note 1*: These rules prevent more than one user-defined conversion
932
  from being applied during overload resolution, thereby avoiding infinite
933
  recursion. — *end note*]
934
 
935
  [*Example 1*:
936
 
937
  ``` cpp
938
  struct Y { Y(int); };
939
  struct A { operator int(); };
940
  Y y1 = A(); // error: A::operator int() is not a candidate
941
 
942
- struct X { };
943
  struct B { operator X(); };
944
  B b;
945
- X x({b}); // error: B::operator X() is not a candidate
946
  ```
947
 
948
  — *end example*]
949
 
950
  For the case where the parameter type is a reference, see 
@@ -954,12 +1300,12 @@ When the parameter type is not a reference, the implicit conversion
954
  sequence models a copy-initialization of the parameter from the argument
955
  expression. The implicit conversion sequence is the one required to
956
  convert the argument expression to a prvalue of the type of the
957
  parameter.
958
 
959
- [*Note 2*: When the parameter has a class type, this is a conceptual
960
- conversion defined for the purposes of Clause  [[over]]; the actual
961
  initialization is defined in terms of constructors and is not a
962
  conversion. — *end note*]
963
 
964
  Any difference in top-level cv-qualification is subsumed by the
965
  initialization itself and does not constitute a conversion.
@@ -971,39 +1317,39 @@ case is the identity sequence; it contains no “conversion” from
971
 
972
  When the parameter has a class type and the argument expression has the
973
  same type, the implicit conversion sequence is an identity conversion.
974
  When the parameter has a class type and the argument expression has a
975
  derived class type, the implicit conversion sequence is a
976
- derived-to-base Conversion from the derived class to the base class.
977
 
978
- [*Note 3*: There is no such standard conversion; this derived-to-base
979
- Conversion exists only in the description of implicit conversion
980
  sequences. — *end note*]
981
 
982
- A derived-to-base Conversion has Conversion rank ([[over.ics.scs]]).
983
 
984
  In all contexts, when converting to the implicit object parameter or
985
  when converting to the left operand of an assignment operation only
986
  standard conversion sequences are allowed.
987
 
988
  If no conversions are required to match an argument to a parameter type,
989
  the implicit conversion sequence is the standard conversion sequence
990
- consisting of the identity conversion ([[over.ics.scs]]).
991
 
992
  If no sequence of conversions can be found to convert an argument to a
993
  parameter type, an implicit conversion sequence cannot be formed.
994
 
995
- If several different sequences of conversions exist that each convert
996
- the argument to the parameter type, the implicit conversion sequence
997
- associated with the parameter is defined to be the unique conversion
998
- sequence designated the *ambiguous conversion sequence*. For the purpose
999
- of ranking implicit conversion sequences as described in 
1000
  [[over.ics.rank]], the ambiguous conversion sequence is treated as a
1001
  user-defined conversion sequence that is indistinguishable from any
1002
  other user-defined conversion sequence.
1003
 
1004
- [*Note 4*:
1005
 
1006
  This rule prevents a function from becoming non-viable because of an
1007
  ambiguous conversion sequence for one of its parameters.
1008
 
1009
  [*Example 3*:
@@ -1014,11 +1360,11 @@ class A { A (B&);};
1014
  class B { operator A (); };
1015
  class C { C (B&); };
1016
  void f(A) { }
1017
  void f(C) { }
1018
  B b;
1019
- f(b); // ill-formed: ambiguous because there is a conversion b → C (via constructor)
1020
  // and an (ambiguous) conversion b → A (via constructor or conversion function)
1021
  void f(B) { }
1022
  f(b); // OK, unambiguous
1023
  ```
1024
 
@@ -1033,69 +1379,66 @@ conversion of one of the arguments in the call is ambiguous.
1033
  The three forms of implicit conversion sequences mentioned above are
1034
  defined in the following subclauses.
1035
 
1036
  ##### Standard conversion sequences <a id="over.ics.scs">[[over.ics.scs]]</a>
1037
 
1038
- Table  [[tab:over.conversions]] summarizes the conversions defined in
1039
- Clause  [[conv]] and partitions them into four disjoint categories:
1040
- Lvalue Transformation, Qualification Adjustment, Promotion, and
1041
- Conversion.
1042
 
1043
- [*Note 5*: These categories are orthogonal with respect to value
1044
  category, cv-qualification, and data representation: the Lvalue
1045
  Transformations do not change the cv-qualification or data
1046
  representation of the type; the Qualification Adjustments do not change
1047
  the value category or data representation of the type; and the
1048
  Promotions and Conversions do not change the value category or
1049
  cv-qualification of the type. — *end note*]
1050
 
1051
- [*Note 6*: As described in Clause  [[conv]], a standard conversion
1052
- sequence is either the Identity conversion by itself (that is, no
1053
- conversion) or consists of one to three conversions from the other four
1054
- categories. If there are two or more conversions in the sequence, the
1055
- conversions are applied in the canonical order: **Lvalue
1056
- Transformation**, **Promotion** or **Conversion**, **Qualification
1057
- Adjustment**. — *end note*]
1058
 
1059
- Each conversion in Table  [[tab:over.conversions]] also has an
1060
- associated rank (Exact Match, Promotion, or Conversion). These are used
1061
- to rank standard conversion sequences ([[over.ics.rank]]). The rank of
1062
- a conversion sequence is determined by considering the rank of each
1063
- conversion in the sequence and the rank of any reference binding (
1064
- [[over.ics.ref]]). If any of those has Conversion rank, the sequence has
1065
- Conversion rank; otherwise, if any of those has Promotion rank, the
1066
- sequence has Promotion rank; otherwise, the sequence has Exact Match
1067
- rank.
1068
 
1069
- **Table: Conversions** <a id="tab:over.conversions">[tab:over.conversions]</a>
1070
 
1071
  | Conversion | Category | Rank | Subclause |
1072
  | ----------------------- | -------- | ---- | ----------------- |
1073
  | No conversions required | Identity | | |
1074
  | Integral promotions | | | [[conv.prom]] |
1075
  | Integral conversions | | | [[conv.integral]] |
1076
 
1077
 
1078
  ##### User-defined conversion sequences <a id="over.ics.user">[[over.ics.user]]</a>
1079
 
1080
- A user-defined conversion sequence consists of an initial standard
1081
- conversion sequence followed by a user-defined conversion (
1082
- [[class.conv]]) followed by a second standard conversion sequence. If
1083
- the user-defined conversion is specified by a constructor (
1084
- [[class.conv.ctor]]), the initial standard conversion sequence converts
1085
- the source type to the type required by the argument of the constructor.
1086
- If the user-defined conversion is specified by a conversion function (
1087
- [[class.conv.fct]]), the initial standard conversion sequence converts
1088
- the source type to the implicit object parameter of the conversion
1089
- function.
1090
 
1091
  The second standard conversion sequence converts the result of the
1092
- user-defined conversion to the target type for the sequence. Since an
1093
- implicit conversion sequence is an initialization, the special rules for
1094
- initialization by user-defined conversion apply when selecting the best
1095
- user-defined conversion for a user-defined conversion sequence (see 
1096
- [[over.match.best]] and  [[over.best.ics]]).
 
1097
 
1098
  If the user-defined conversion is specified by a specialization of a
1099
  conversion function template, the second standard conversion sequence
1100
  shall have exact match rank.
1101
 
@@ -1111,15 +1454,15 @@ An ellipsis conversion sequence occurs when an argument in a function
1111
  call is matched with the ellipsis parameter specification of the
1112
  function called (see  [[expr.call]]).
1113
 
1114
  ##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
1115
 
1116
- When a parameter of reference type binds directly ([[dcl.init.ref]]) to
1117
- an argument expression, the implicit conversion sequence is the identity
1118
  conversion, unless the argument expression has a type that is a derived
1119
  class of the parameter type, in which case the implicit conversion
1120
- sequence is a derived-to-base Conversion ([[over.best.ics]]).
1121
 
1122
  [*Example 4*:
1123
 
1124
  ``` cpp
1125
  struct A {};
@@ -1131,73 +1474,108 @@ int i = f(b); // calls f(B&), an exact match, rather than f(A&), a convers
1131
 
1132
  — *end example*]
1133
 
1134
  If the parameter binds directly to the result of applying a conversion
1135
  function to the argument expression, the implicit conversion sequence is
1136
- a user-defined conversion sequence ([[over.ics.user]]), with the second
1137
  standard conversion sequence either an identity conversion or, if the
1138
  conversion function returns an entity of a type that is a derived class
1139
- of the parameter type, a derived-to-base Conversion.
1140
 
1141
  When a parameter of reference type is not bound directly to an argument
1142
  expression, the conversion sequence is the one required to convert the
1143
  argument expression to the referenced type according to 
1144
  [[over.best.ics]]. Conceptually, this conversion sequence corresponds to
1145
  copy-initializing a temporary of the referenced type with the argument
1146
  expression. Any difference in top-level cv-qualification is subsumed by
1147
  the initialization itself and does not constitute a conversion.
1148
 
1149
  Except for an implicit object parameter, for which see 
1150
- [[over.match.funcs]], a standard conversion sequence cannot be formed if
1151
- it requires binding an lvalue reference other than a reference to a
1152
  non-volatile `const` type to an rvalue or binding an rvalue reference to
1153
  an lvalue other than a function lvalue.
1154
 
1155
- [*Note 7*: This means, for example, that a candidate function cannot be
1156
  a viable function if it has a non-`const` lvalue reference parameter
1157
  (other than the implicit object parameter) and the corresponding
1158
  argument would require a temporary to be created to initialize the
1159
  lvalue reference (see  [[dcl.init.ref]]). — *end note*]
1160
 
1161
  Other restrictions on binding a reference to a particular argument that
1162
  are not based on the types of the reference and the argument do not
1163
- affect the formation of a standard conversion sequence, however.
1164
 
1165
  [*Example 5*: A function with an “lvalue reference to `int`” parameter
1166
  can be a viable candidate even if the corresponding argument is an `int`
1167
  bit-field. The formation of implicit conversion sequences treats the
1168
  `int` bit-field as an `int` lvalue and finds an exact match with the
1169
  parameter. If the function is selected by overload resolution, the call
1170
  will nonetheless be ill-formed because of the prohibition on binding a
1171
- non-`const` lvalue reference to a bit-field (
1172
- [[dcl.init.ref]]). — *end example*]
1173
 
1174
  ##### List-initialization sequence <a id="over.ics.list">[[over.ics.list]]</a>
1175
 
1176
- When an argument is an initializer list ([[dcl.init.list]]), it is not
1177
- an expression and special rules apply for converting it to a parameter
1178
  type.
1179
 
1180
- If the parameter type is an aggregate class `X` and the initializer list
1181
- has a single element of type cv `U`, where `U` is `X` or a class derived
1182
- from `X`, the implicit conversion sequence is the one required to
1183
- convert the element to the parameter type.
 
 
1184
 
1185
- Otherwise, if the parameter type is a character array [^11] and the
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1186
  initializer list has a single element that is an appropriately-typed
1187
- string literal ([[dcl.init.string]]), the implicit conversion sequence
1188
  is the identity conversion.
1189
 
1190
  Otherwise, if the parameter type is `std::initializer_list<X>` and all
1191
  the elements of the initializer list can be implicitly converted to `X`,
1192
  the implicit conversion sequence is the worst conversion necessary to
1193
  convert an element of the list to `X`, or if the initializer list has no
1194
  elements, the identity conversion. This conversion can be a user-defined
1195
  conversion even in the context of a call to an initializer-list
1196
  constructor.
1197
 
1198
- [*Example 6*:
1199
 
1200
  ``` cpp
1201
  void f(std::initializer_list<int>);
1202
  f( {} ); // OK: f(initializer_list<int>) identity conversion
1203
  f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
@@ -1219,15 +1597,16 @@ void h(const IA&);
1219
  h({ 1, 2, 3 }); // OK: identity conversion
1220
  ```
1221
 
1222
  — *end example*]
1223
 
1224
- Otherwise, if the parameter type is “array of `N` `X`”, if there exists
1225
- an implicit conversion sequence for each element of the array from the
1226
- corresponding element of the initializer list (or from `{}` if there is
1227
- no such element), the implicit conversion sequence is the worst such
1228
- implicit conversion sequence.
 
1229
 
1230
  Otherwise, if the parameter is a non-aggregate class `X` and overload
1231
  resolution per  [[over.match.list]] chooses a single best constructor
1232
  `C` of `X` to perform the initialization of an object of type `X` from
1233
  the argument initializer list:
@@ -1244,11 +1623,11 @@ If multiple constructors are viable but none is better than the others,
1244
  the implicit conversion sequence is the ambiguous conversion sequence.
1245
  User-defined conversions are allowed for conversion of the initializer
1246
  list elements to the constructor parameter types except as noted in 
1247
  [[over.best.ics]].
1248
 
1249
- [*Example 7*:
1250
 
1251
  ``` cpp
1252
  struct A {
1253
  A(std::initializer_list<int>);
1254
  };
@@ -1280,15 +1659,15 @@ i({ {1,2}, {"bar"} }); // OK: i(D(A(std::initializer_list<int>{1,2\), C(std::st
1280
 
1281
  — *end example*]
1282
 
1283
  Otherwise, if the parameter has an aggregate type which can be
1284
  initialized from the initializer list according to the rules for
1285
- aggregate initialization ([[dcl.init.aggr]]), the implicit conversion
1286
  sequence is a user-defined conversion sequence with the second standard
1287
  conversion sequence an identity conversion.
1288
 
1289
- [*Example 8*:
1290
 
1291
  ``` cpp
1292
  struct A {
1293
  int m1;
1294
  double m2;
@@ -1301,14 +1680,14 @@ f( {1.0} ); // error: narrowing
1301
 
1302
  — *end example*]
1303
 
1304
  Otherwise, if the parameter is a reference, see  [[over.ics.ref]].
1305
 
1306
- [*Note 8*: The rules in this section will apply for initializing the
1307
  underlying temporary for the reference. — *end note*]
1308
 
1309
- [*Example 9*:
1310
 
1311
  ``` cpp
1312
  struct A {
1313
  int m1;
1314
  double m2;
@@ -1327,21 +1706,21 @@ g({1}); // same conversion as int to double
1327
  Otherwise, if the parameter type is not a class:
1328
 
1329
  - if the initializer list has one element that is not itself an
1330
  initializer list, the implicit conversion sequence is the one required
1331
  to convert the element to the parameter type;
1332
- \[*Example 10*:
1333
  ``` cpp
1334
  void f(int);
1335
  f( {'a'} ); // OK: same conversion as char to int
1336
  f( {1.0} ); // error: narrowing
1337
  ```
1338
 
1339
  — *end example*]
1340
  - if the initializer list has no elements, the implicit conversion
1341
  sequence is the identity conversion.
1342
- \[*Example 11*:
1343
  ``` cpp
1344
  void f(int);
1345
  f( { } ); // OK: identity conversion
1346
  ```
1347
 
@@ -1361,26 +1740,28 @@ sequence S1 is neither better than nor worse than conversion sequence
1361
  S2, S1 and S2 are said to be *indistinguishable conversion sequences*.
1362
 
1363
  When comparing the basic forms of implicit conversion sequences (as
1364
  defined in  [[over.best.ics]])
1365
 
1366
- - a standard conversion sequence ([[over.ics.scs]]) is a better
1367
- conversion sequence than a user-defined conversion sequence or an
1368
- ellipsis conversion sequence, and
1369
- - a user-defined conversion sequence ([[over.ics.user]]) is a better
1370
- conversion sequence than an ellipsis conversion sequence (
1371
- [[over.ics.ellipsis]]).
1372
 
1373
  Two implicit conversion sequences of the same form are indistinguishable
1374
  conversion sequences unless one of the following rules applies:
1375
 
1376
  - List-initialization sequence `L1` is a better conversion sequence than
1377
  list-initialization sequence `L2` if
1378
  - `L1` converts to `std::initializer_list<X>` for some `X` and `L2`
1379
  does not, or, if not that,
1380
- - `L1` converts to type “array of `N1` `T`”, `L2` converts to type
1381
- “array of `N2` `T`”, and `N1` is smaller than `N2`,
 
 
1382
 
1383
  even if one of the other rules in this paragraph would otherwise
1384
  apply.
1385
  \[*Example 1*:
1386
  ``` cpp
@@ -1391,10 +1772,24 @@ conversion sequences unless one of the following rules applies:
1391
  void f2(std::pair<const char*, const char*>); // #3
1392
  void f2(std::initializer_list<std::string>); // #4
1393
  void g2() { f2({"foo","bar"}); } // chooses #4
1394
  ```
1395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1396
  — *end example*]
1397
  - Standard conversion sequence `S1` is a better conversion sequence than
1398
  standard conversion sequence `S2` if
1399
  - `S1` is a proper subsequence of `S2` (comparing the conversion
1400
  sequences in the canonical form defined by  [[over.ics.scs]],
@@ -1402,15 +1797,15 @@ conversion sequences unless one of the following rules applies:
1402
  sequence is considered to be a subsequence of any non-identity
1403
  conversion sequence) or, if not that,
1404
  - the rank of `S1` is better than the rank of `S2`, or `S1` and `S2`
1405
  have the same rank and are distinguishable by the rules in the
1406
  paragraph below, or, if not that,
1407
- - `S1` and `S2` are reference bindings ([[dcl.init.ref]]) and neither
1408
- refers to an implicit object parameter of a non-static member
1409
- function declared without a *ref-qualifier*, and `S1` binds an
1410
- rvalue reference to an rvalue and `S2` binds an lvalue reference
1411
- \[*Example 2*:
1412
  ``` cpp
1413
  int i;
1414
  int f1();
1415
  int&& f2();
1416
  int g(const int&);
@@ -1434,45 +1829,43 @@ conversion sequences unless one of the following rules applies:
1434
  a.p(); // calls A::p()&
1435
  ```
1436
 
1437
  — *end example*]
1438
  or, if not that,
1439
- - `S1` and `S2` are reference bindings ([[dcl.init.ref]]) and `S1`
1440
  binds an lvalue reference to a function lvalue and `S2` binds an
1441
  rvalue reference to a function lvalue
1442
- \[*Example 3*:
1443
  ``` cpp
1444
  int f(void(&)()); // #1
1445
  int f(void(&&)()); // #2
1446
  void g();
1447
  int i1 = f(g); // calls #1
1448
  ```
1449
 
1450
  — *end example*]
1451
  or, if not that,
1452
- - `S1`
1453
- and `S2` differ only in their qualification conversion and yield
1454
- similar types `T1` and `T2` ([[conv.qual]]), respectively, and the
1455
- cv-qualification signature of type `T1` is a proper subset of the
1456
- cv-qualification signature of type `T2`
1457
- \[*Example 4*:
1458
  ``` cpp
1459
  int f(const volatile int *);
1460
  int f(const int *);
1461
  int i;
1462
  int j = f(&i); // calls f(const int*)
1463
  ```
1464
 
1465
  — *end example*]
1466
  or, if not that,
1467
  - `S1`
1468
- and `S2` are reference bindings ([[dcl.init.ref]]), and the types
1469
  to which the references refer are the same type except for top-level
1470
  cv-qualifiers, and the type to which the reference initialized by
1471
  `S2` refers is more cv-qualified than the type to which the
1472
  reference initialized by `S1` refers.
1473
- \[*Example 5*:
1474
  ``` cpp
1475
  int f(const int &);
1476
  int f(int &);
1477
  int g(const int &);
1478
  int g(int);
@@ -1496,11 +1889,11 @@ conversion sequences unless one of the following rules applies:
1496
  than another user-defined conversion sequence `U2` if they contain the
1497
  same user-defined conversion function or constructor or they
1498
  initialize the same class in an aggregate initialization and in either
1499
  case the second standard conversion sequence of `U1` is better than
1500
  the second standard conversion sequence of `U2`.
1501
- \[*Example 6*:
1502
  ``` cpp
1503
  struct A {
1504
  operator short();
1505
  } a;
1506
  int f(int);
@@ -1514,12 +1907,12 @@ conversion sequences unless one of the following rules applies:
1514
  Standard conversion sequences are ordered by their ranks: an Exact Match
1515
  is a better conversion than a Promotion, which is a better conversion
1516
  than a Conversion. Two conversion sequences with the same rank are
1517
  indistinguishable unless one of the following rules applies:
1518
 
1519
- - A conversion that does not convert a pointer, a pointer to member, or
1520
- `std::nullptr_t` to `bool` is better than one that does.
1521
  - A conversion that promotes an enumeration whose underlying type is
1522
  fixed to its underlying type is better than one that promotes to the
1523
  promoted underlying type, if the two are different.
1524
  - If class `B` is derived directly or indirectly from class `A`,
1525
  conversion of `B*` to `A*` is better than conversion of `B*` to
@@ -1527,11 +1920,11 @@ indistinguishable unless one of the following rules applies:
1527
  of `B*` to `void*`.
1528
  - If class `B` is derived directly or indirectly from class `A` and
1529
  class `C` is derived directly or indirectly from `B`,
1530
  - conversion of `C*` to `B*` is better than conversion of `C*` to
1531
  `A*`,
1532
- \[*Example 7*:
1533
  ``` cpp
1534
  struct A {};
1535
  struct B : public A {};
1536
  struct C : public B {};
1537
  C* pc;
 
15
  context ill-formed. — *end note*]
16
 
17
  Overload resolution selects the function to call in seven distinct
18
  contexts within the language:
19
 
20
+ - invocation of a function named in the function call syntax
21
+ [[over.call.func]];
22
  - invocation of a function call operator, a pointer-to-function
23
  conversion function, a reference-to-pointer-to-function conversion
24
  function, or a reference-to-function conversion function on a class
25
+ object named in the function call syntax [[over.call.object]];
26
+ - invocation of the operator referenced in an expression
27
+ [[over.match.oper]];
28
+ - invocation of a constructor for default- or direct-initialization
29
+ [[dcl.init]] of a class object [[over.match.ctor]];
30
+ - invocation of a user-defined conversion for copy-initialization
31
+ [[dcl.init]] of a class object [[over.match.copy]];
32
  - invocation of a conversion function for initialization of an object of
33
+ a non-class type from an expression of class type [[over.match.conv]];
34
+ and
35
+ - invocation of a conversion function for conversion in which a
36
+ reference [[dcl.init.ref]] will be directly bound [[over.match.ref]].
 
37
 
38
  Each of these contexts defines the set of candidate functions and the
39
  list of arguments in its own unique way. But, once the candidate
40
  functions and argument lists have been identified, the selection of the
41
  best function is the same in all cases:
42
 
43
  - First, a subset of the candidate functions (those that have the proper
44
  number of arguments and meet certain other conditions) is selected to
45
+ form a set of viable functions [[over.match.viable]].
46
  - Then the best viable function is selected based on the implicit
47
+ conversion sequences [[over.best.ics]] needed to match each argument
48
+ to the corresponding parameter of each viable function.
49
 
50
  If a best viable function exists and is unique, overload resolution
51
  succeeds and produces it as the result. Otherwise overload resolution
52
  fails and the invocation is ill-formed. When overload resolution
53
+ succeeds, and the best viable function is not accessible
54
+ [[class.access]] in the context in which it is used, the program is
55
  ill-formed.
56
 
57
+ Overload resolution results in a *usable candidate* if overload
58
+ resolution succeeds and the selected candidate is either not a function
59
+ [[over.built]], or is a function that is not deleted and is accessible
60
+ from the context in which overload resolution was performed.
61
+
62
  ### Candidate functions and argument lists <a id="over.match.funcs">[[over.match.funcs]]</a>
63
 
64
  The subclauses of  [[over.match.funcs]] describe the set of candidate
65
  functions and the argument list submitted to overload resolution in each
66
+ context in which overload resolution is used. The source transformations
67
+ and constructions defined in these subclauses are only for the purpose
68
+ of describing the overload resolution process. An implementation is not
69
+ required to use such transformations and constructions.
 
70
 
71
  The set of candidate functions can contain both member and non-member
72
  functions to be resolved against the same argument list. So that
73
  argument and parameter lists are comparable within this heterogeneous
74
+ set, a member function is considered to have an extra first parameter,
75
+ called the *implicit object parameter*, which represents the object for
76
+ which the member function has been called. For the purposes of overload
77
  resolution, both static and non-static member functions have an implicit
78
  object parameter, but constructors do not.
79
 
80
  Similarly, when appropriate, the context can construct an argument list
81
+ that contains an *implied object argument* as the first argument in the
82
+ list to denote the object to be operated on.
 
 
 
83
 
84
  For non-static member functions, the type of the implicit object
85
  parameter is
86
 
87
  - “lvalue reference to cv `X`” for functions declared without a
 
105
  functions, the implicit object parameter is considered to match any
106
  object (since if the function is selected, the object is discarded).
107
 
108
  [*Note 1*: No actual type is established for the implicit object
109
  parameter of a static member function, and no attempt will be made to
110
+ determine a conversion sequence for that parameter
111
+ [[over.match.best]]. — *end note*]
112
 
113
  During overload resolution, the implied object argument is
114
  indistinguishable from other arguments. The implicit object parameter,
115
  however, retains its identity since no user-defined conversions can be
116
  applied to achieve a type match with it. For non-static member functions
117
+ declared without a *ref-qualifier*, even if the implicit object
118
+ parameter is not const-qualified, an rvalue can be bound to the
119
+ parameter as long as in all other respects the argument can be converted
120
+ to the type of the implicit object parameter.
121
 
122
+ [*Note 2*: The fact that such an argument is an rvalue does not affect
123
+ the ranking of implicit conversion sequences
124
+ [[over.ics.rank]]. *end note*]
 
 
 
125
 
126
  Because other than in list-initialization only one user-defined
127
  conversion is allowed in an implicit conversion sequence, special rules
128
  apply when selecting the best user-defined conversion (
129
  [[over.match.best]], [[over.best.ics]]).
 
138
 
139
  class C : T {
140
  public:
141
  C(int);
142
  };
143
+ T a = 1; // error: no viable conversion (T(C(1)) not considered)
144
  ```
145
 
146
  — *end example*]
147
 
148
  In each case where a candidate is a function template, candidate
149
  function template specializations are generated using template argument
150
+ deduction ([[temp.over]], [[temp.deduct]]). If a constructor template
151
+ or conversion function template has an *explicit-specifier* whose
152
+ *constant-expression* is value-dependent [[temp.dep]], template argument
153
+ deduction is performed first and then, if the context requires a
154
+ candidate that is not explicit and the generated specialization is
155
+ explicit [[dcl.fct.spec]], it will be removed from the candidate set.
156
+ Those candidates are then handled as candidate functions in the usual
157
+ way.[^2] A given name can refer to one or more function templates and
158
+ also to a set of non-template functions. In such a case, the candidate
159
+ functions generated from each function template are combined with the
160
+ set of non-template candidate functions.
161
+
162
+ A defaulted move special member function ([[class.copy.ctor]],
163
+ [[class.copy.assign]]) that is defined as deleted is excluded from the
164
+ set of candidate functions in all contexts. A constructor inherited from
165
+ class type `C` [[class.inhctor.init]] that has a first parameter of type
166
+ “reference to *cv1* `P`” (including such a constructor instantiated from
167
+ a template) is excluded from the set of candidate functions when
168
+ constructing an object of type *cv2* `D` if the argument list has
169
+ exactly one argument and `C` is reference-related to `P` and `P` is
170
+ reference-related to `D`.
171
+
172
+ [*Example 3*:
173
+
174
+ ``` cpp
175
+ struct A {
176
+ A(); // #1
177
+ A(A &&); // #2
178
+ template<typename T> A(T &&); // #3
179
+ };
180
+ struct B : A {
181
+ using A::A;
182
+ B(const B &); // #4
183
+ B(B &&) = default; // #5, implicitly deleted
184
+
185
+ struct X { X(X &&) = delete; } x;
186
+ };
187
+ extern B b1;
188
+ B b2 = static_cast<B&&>(b1); // calls #4: #1 is not viable, #2, #3, and #5 are not candidates
189
+ struct C { operator B&&(); };
190
+ B b3 = C(); // calls #4
191
+ ```
192
+
193
+ — *end example*]
194
 
195
  #### Function call syntax <a id="over.match.call">[[over.match.call]]</a>
196
 
197
+ In a function call [[expr.call]]
198
 
199
  ``` bnf
200
  postfix-expression '(' expression-listₒₚₜ ')'
201
  ```
202
 
203
+ if the *postfix-expression* names at least one function or function
204
+ template, overload resolution is applied as specified in
205
  [[over.call.func]]. If the *postfix-expression* denotes an object of
206
  class type, overload resolution is applied as specified in
207
  [[over.call.object]].
208
 
209
+ If the *postfix-expression* is the address of an overload set, overload
210
+ resolution is applied using that set as described above. If the function
211
+ selected by overload resolution is a non-static member function, the
212
+ program is ill-formed.
213
 
214
  [*Note 1*: The resolution of the address of an overload set in other
215
  contexts is described in [[over.over]]. — *end note*]
216
 
217
  ##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
 
233
  function calls and unqualified function calls.
234
 
235
  In qualified function calls, the name to be resolved is an
236
  *id-expression* and is preceded by an `->` or `.` operator. Since the
237
  construct `A->B` is generally equivalent to `(*A).B`, the rest of
238
+ [[over]] assumes, without loss of generality, that all member function
239
+ calls have been normalized to the form that uses an object and the `.`
240
+ operator. Furthermore, [[over]] assumes that the *postfix-expression*
241
+ that is the left operand of the `.` operator has type “cv `T`” where `T`
242
+ denotes a class.[^3] Under this assumption, the *id-expression* in the
243
+ call is looked up as a member function of `T` following the rules for
244
+ looking up names in classes [[class.member.lookup]]. The function
245
+ declarations found by that lookup constitute the set of candidate
246
+ functions. The argument list is the *expression-list* in the call
247
+ augmented by the addition of the left operand of the `.` operator in the
248
+ normalized member function call as the implied object argument
249
+ [[over.match.funcs]].
250
 
251
  In unqualified function calls, the name is not qualified by an `->` or
252
  `.` operator and has the more general form of a *primary-expression*.
253
  The name is looked up in the context of the function call following the
254
+ normal rules for name lookup in expressions [[basic.lookup]]. The
255
  function declarations found by that lookup constitute the set of
256
  candidate functions. Because of the rules for name lookup, the set of
257
  candidate functions consists (1) entirely of non-member functions or (2)
258
  entirely of member functions of some class `T`. In case (1), the
259
  argument list is the same as the *expression-list* in the call. In case
260
  (2), the argument list is the *expression-list* in the call augmented by
261
  the addition of an implied object argument as in a qualified function
262
+ call. If the keyword `this` [[class.this]] is in scope and refers to
263
  class `T`, or a derived class of `T`, then the implied object argument
264
  is `(*this)`. If the keyword `this` is not in scope or refers to another
265
  class, then a contrived object of type `T` becomes the implied object
266
+ argument.[^4] If the argument list is augmented by a contrived object
267
  and overload resolution selects one of the non-static member functions
268
  of `T`, the call is ill-formed.
269
 
270
  ##### Call to object of class type <a id="over.call.object">[[over.call.object]]</a>
271
 
272
+ If the *postfix-expression* `E` in the function call syntax evaluates to
273
  a class object of type “cv `T`”, then the set of candidate functions
274
  includes at least the function call operators of `T`. The function call
275
  operators of `T` are obtained by ordinary lookup of the name
276
  `operator()` in the context of `(E).operator()`.
277
 
278
  In addition, for each non-explicit conversion function declared in `T`
279
  of the form
280
 
281
  ``` bnf
282
+ operator conversion-type-id '( )' cv-qualifier-seqₒₚₜ ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ ';'
283
  ```
284
 
285
+ where the optional *cv-qualifier-seq* is the same cv-qualification as,
286
+ or a greater cv-qualification than, cv, and where *conversion-type-id*
287
+ denotes the type “pointer to function of (`P₁`, …, `Pₙ`) returning `R`”,
288
+ or the type “reference to pointer to function of (`P₁`, …, `Pₙ`)
289
+ returning `R`”, or the type “reference to function of (`P₁`, …, `Pₙ`)
290
+ returning `R`”, a *surrogate call function* with the unique name
291
+ *call-function* and having the form
292
 
293
  ``` bnf
294
+ 'R' *call-function* '(' conversion-type-id \ %
295
  'F, P₁ a₁, …, Pₙ aₙ)' '{ return F (a₁, …, aₙ); }'
296
  ```
297
 
298
  is also considered as a candidate function. Similarly, surrogate call
299
  functions are added to the set of candidate functions for each
300
  non-explicit conversion function declared in a base class of `T`
301
  provided the function is not hidden within `T` by another intervening
302
+ declaration.[^5]
 
 
 
 
 
 
 
303
 
304
  The argument list submitted to overload resolution consists of the
305
  argument expressions present in the function call syntax preceded by the
306
  implied object argument `(E)`.
307
 
 
333
 
334
  #### Operators in expressions <a id="over.match.oper">[[over.match.oper]]</a>
335
 
336
  If no operand of an operator in an expression has a type that is a class
337
  or an enumeration, the operator is assumed to be a built-in operator and
338
+ interpreted according to [[expr.compound]].
339
 
340
  [*Note 1*: Because `.`, `.*`, and `::` cannot be overloaded, these
341
+ operators are always built-in operators interpreted according to
342
+ [[expr.compound]]. `?:` cannot be overloaded, but the rules in this
343
+ subclause are used to determine the conversions to be applied to the
344
+ second and third operands when they have class or enumeration type
345
+ [[expr.cond]]. — *end note*]
346
 
347
  [*Example 1*:
348
 
349
  ``` cpp
350
  struct String {
 
353
  operator const char* ();
354
  };
355
  String operator + (const String&, const String&);
356
 
357
  void f() {
358
+ const char* p= "one" + "two"; // error: cannot add two pointers; overloaded operator+ not considered
359
+ // because neither operand has class or enumeration type
360
  int I = 1 + 1; // always evaluates to 2 even if class or enumeration types exist
361
  // that would perform the operation.
362
  }
363
  ```
364
 
 
369
  operator or a user-defined conversion can be necessary to convert the
370
  operand to a type that is appropriate for a built-in operator. In this
371
  case, overload resolution is used to determine which operator function
372
  or built-in operator is to be invoked to implement the operator.
373
  Therefore, the operator notation is first transformed to the equivalent
374
+ function-call notation as summarized in [[over.match.oper]] (where `@`
375
+ denotes one of the operators covered in the specified subclause).
376
+ However, the operands are sequenced in the order prescribed for the
377
+ built-in operator [[expr.compound]].
378
 
379
+ **Table: Relationship between operator and function call notation** <a id="over.match.oper">[over.match.oper]</a>
380
 
381
  | Subclause | Expression | As member function | As non-member function |
382
  | ------------ | ---------- | ------------------- | ---------------------- |
383
  | (a)} |
384
  | (a, b)} |
 
386
  | [[over.sub]] | `a[b]` | `(a).operator[](b)` | |
387
  | [[over.ref]] | `a->` | `(a).operator->( )` | |
388
  | (a, 0)} |
389
 
390
 
391
+ For a unary operator `@` with an operand of type *cv1* `T1`, and for a
392
+ binary operator `@` with a left operand of type *cv1* `T1` and a right
393
+ operand of type *cv2* `T2`, four sets of candidate functions, designated
394
+ *member candidates*, *non-member candidates*, *built-in candidates*, and
395
+ *rewritten candidates*, are constructed as follows:
 
396
 
397
  - If `T1` is a complete class type or a class currently being defined,
398
  the set of member candidates is the result of the qualified lookup of
399
+ `T1::operator@` [[over.call.func]]; otherwise, the set of member
400
  candidates is empty.
401
  - The set of non-member candidates is the result of the unqualified
402
  lookup of `operator@` in the context of the expression according to
403
+ the usual rules for name lookup in unqualified function calls
404
+ [[basic.lookup.argdep]] except that all member functions are ignored.
405
  However, if no operand has a class type, only those non-member
406
  functions in the lookup set that have a first parameter of type `T1`
407
  or “reference to cv `T1`”, when `T1` is an enumeration type, or (if
408
  there is a right operand) a second parameter of type `T2` or
409
  “reference to cv `T2`”, when `T2` is an enumeration type, are
 
416
  - accept the same number of operands, and
417
  - accept operand types to which the given operand or operands can be
418
  converted according to [[over.best.ics]], and
419
  - do not have the same parameter-type-list as any non-member candidate
420
  that is not a function template specialization.
421
+ - The rewritten candidate set is determined as follows:
422
+ - For the relational [[expr.rel]] operators, the rewritten candidates
423
+ include all non-rewritten candidates for the expression `x <=> y`.
424
+ - For the relational [[expr.rel]] and three-way comparison
425
+ [[expr.spaceship]] operators, the rewritten candidates also include
426
+ a synthesized candidate, with the order of the two parameters
427
+ reversed, for each non-rewritten candidate for the expression
428
+ `y <=> x`.
429
+ - For the `!=` operator [[expr.eq]], the rewritten candidates include
430
+ all non-rewritten candidates for the expression `x == y`.
431
+ - For the equality operators, the rewritten candidates also include a
432
+ synthesized candidate, with the order of the two parameters
433
+ reversed, for each non-rewritten candidate for the expression
434
+ `y == x`.
435
+ - For all other operators, the rewritten candidate set is empty.
436
+
437
+ \[*Note 2*: A candidate synthesized from a member candidate has its
438
+ implicit object parameter as the second parameter, thus implicit
439
+ conversions are considered for the first, but not for the second,
440
+ parameter. — *end note*]
441
 
442
  For the built-in assignment operators, conversions of the left operand
443
  are restricted as follows:
444
 
445
  - no temporaries are introduced to hold the left operand, and
446
  - no user-defined conversions are applied to the left operand to achieve
447
  a type match with the left-most parameter of a built-in candidate.
448
 
449
  For all other operators, no such restrictions apply.
450
 
451
+ The set of candidate functions for overload resolution for some operator
452
+ `@` is the union of the member candidates, the non-member candidates,
453
+ the built-in candidates, and the rewritten candidates for that operator
454
+ `@`.
455
+
456
+ The argument list contains all of the operands of the operator. The best
457
+ function from the set of candidate functions is selected according to 
458
+ [[over.match.viable]] and  [[over.match.best]].[^6]
459
 
460
  [*Example 2*:
461
 
462
  ``` cpp
463
  struct A {
 
470
  }
471
  ```
472
 
473
  — *end example*]
474
 
475
+ If a rewritten `operator<=>` candidate is selected by overload
476
+ resolution for an operator `@`, `x @ y` is interpreted as
477
+ `0 @ (y <=> x)` if the selected candidate is a synthesized candidate
478
+ with reversed order of parameters, or `(x <=> y) @ 0` otherwise, using
479
+ the selected rewritten `operator<=>` candidate. Rewritten candidates for
480
+ the operator `@` are not considered in the context of the resulting
481
+ expression.
482
+
483
+ If a rewritten `operator==` candidate is selected by overload resolution
484
+ for an operator `@`, its return type shall be cv `bool`, and `x @ y` is
485
+ interpreted as:
486
+
487
+ - if `@` is `!=` and the selected candidate is a synthesized candidate
488
+ with reversed order of parameters, `!(y == x)`,
489
+ - otherwise, if `@` is `!=`, `!(x == y)`,
490
+ - otherwise (when `@` is `==`), `y == x`,
491
+
492
+ in each case using the selected rewritten `operator==` candidate.
493
+
494
  If a built-in candidate is selected by overload resolution, the operands
495
  of class type are converted to the types of the corresponding parameters
496
  of the selected operation function, except that the second standard
497
+ conversion sequence of a user-defined conversion sequence
498
+ [[over.ics.user]] is not applied. Then the operator is treated as the
499
+ corresponding built-in operator and interpreted according to
500
+ [[expr.compound]].
501
 
502
  [*Example 3*:
503
 
504
  ``` cpp
505
  struct X {
 
521
  function is called. When `operator->` returns, the operator `->` is
522
  applied to the value returned, with the original second operand.[^7]
523
 
524
  If the operator is the operator `,`, the unary operator `&`, or the
525
  operator `->`, and there are no viable functions, then the operator is
526
+ assumed to be the built-in operator and interpreted according to
527
+ [[expr.compound]].
528
 
529
+ [*Note 3*:
530
 
531
  The lookup rules for operators in expressions are different than the
532
  lookup rules for operator function names in a function call, as shown in
533
  the following example:
534
 
 
551
 
552
  — *end note*]
553
 
554
  #### Initialization by constructor <a id="over.match.ctor">[[over.match.ctor]]</a>
555
 
556
+ When objects of class type are direct-initialized [[dcl.init]],
557
+ copy-initialized from an expression of the same or a derived class type
558
+ [[dcl.init]], or default-initialized [[dcl.init]], overload resolution
559
+ selects the constructor. For direct-initialization or
560
  default-initialization that is not in the context of
561
  copy-initialization, the candidate functions are all the constructors of
562
+ the class of the object being initialized. For copy-initialization
563
+ (including default initialization in the context of
564
+ copy-initialization), the candidate functions are all the converting
565
+ constructors [[class.conv.ctor]] of that class. The argument list is the
566
  *expression-list* or *assignment-expression* of the *initializer*.
567
 
568
  #### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
569
 
570
  Under the conditions specified in  [[dcl.init]], as part of a
 
578
  corresponding non-reference copy-initialization. — *end note*]
579
 
580
  Assuming that “*cv1* `T`” is the type of the object being initialized,
581
  with `T` a class type, the candidate functions are selected as follows:
582
 
583
+ - The converting constructors [[class.conv.ctor]] of `T` are candidate
584
+ functions.
585
  - When the type of the initializer expression is a class type “cv `S`”,
586
  the non-explicit conversion functions of `S` and its base classes are
587
+ considered. When initializing a temporary object [[class.mem]] to be
588
+ bound to the first parameter of a constructor where the parameter is
589
+ of type “reference to *cv2* `T`” and the constructor is called with a
590
  single argument in the context of direct-initialization of an object
591
+ of type “*cv3* `T`”, explicit conversion functions are also
592
  considered. Those that are not hidden within `S` and yield a type
593
  whose cv-unqualified version is the same type as `T` or is a derived
594
+ class thereof are candidate functions. A call to a conversion function
595
+ returning “reference to `X`” is a glvalue of type `X`, and such a
596
+ conversion function is therefore considered to yield `X` for this
597
+ process of selecting candidate functions.
598
 
599
  In both cases, the argument list has one argument, which is the
600
  initializer expression.
601
 
602
  [*Note 2*: This argument will be compared against the first parameter
 
615
  functions are selected as follows:
616
 
617
  - The conversion functions of `S` and its base classes are considered.
618
  Those non-explicit conversion functions that are not hidden within `S`
619
  and yield type `T` or a type that can be converted to type `T` via a
620
+ standard conversion sequence [[over.ics.scs]] are candidate functions.
621
+ For direct-initialization, those explicit conversion functions that
622
+ are not hidden within `S` and yield type `T` or a type that can be
623
+ converted to type `T` with a qualification conversion [[conv.qual]]
624
+ are also candidate functions. Conversion functions that return a
625
+ cv-qualified type are considered to yield the cv-unqualified version
626
+ of that type for this process of selecting candidate functions. A call
627
+ to a conversion function returning “reference to `X`” is a glvalue of
628
+ type `X`, and such a conversion function is therefore considered to
629
+ yield `X` for this process of selecting candidate functions.
 
630
 
631
  The argument list has one argument, which is the initializer expression.
632
 
633
  [*Note 1*: This argument will be compared against the implicit object
634
  parameter of the conversion functions. — *end note*]
635
 
636
  #### Initialization by conversion function for direct reference binding <a id="over.match.ref">[[over.match.ref]]</a>
637
 
638
  Under the conditions specified in  [[dcl.init.ref]], a reference can be
639
+ bound directly to the result of applying a conversion function to an
640
+ initializer expression. Overload resolution is used to select the
641
+ conversion function to be invoked. Assuming that “reference to *cv1*
642
+ `T`” is the type of the reference being initialized, and “cv `S`” is the
643
+ type of the initializer expression, with `S` a class type, the candidate
644
+ functions are selected as follows:
 
645
 
646
  - The conversion functions of `S` and its base classes are considered.
647
  Those non-explicit conversion functions that are not hidden within `S`
648
  and yield type “lvalue reference to *cv2* `T2`” (when initializing an
649
  lvalue reference or an rvalue reference to function) or “*cv2* `T2`”
650
  or “rvalue reference to *cv2* `T2`” (when initializing an rvalue
651
  reference or an lvalue reference to function), where “*cv1* `T`” is
652
+ reference-compatible [[dcl.init.ref]] with “*cv2* `T2`”, are candidate
653
+ functions. For direct-initialization, those explicit conversion
654
+ functions that are not hidden within `S` and yield type “lvalue
655
+ reference to *cv2* `T2`” (when initializing an lvalue reference or an
656
+ rvalue reference to function) or “rvalue reference to *cv2* `T2`
657
+ (when initializing an rvalue reference or an lvalue reference to
658
+ function), where `T2` is the same type as `T` or can be converted to
659
+ type `T` with a qualification conversion [[conv.qual]], are also
660
+ candidate functions.
661
 
662
  The argument list has one argument, which is the initializer expression.
663
 
664
  [*Note 1*: This argument will be compared against the implicit object
665
  parameter of the conversion functions. — *end note*]
666
 
667
  #### Initialization by list-initialization <a id="over.match.list">[[over.match.list]]</a>
668
 
669
  When objects of non-aggregate class type `T` are list-initialized such
670
  that [[dcl.init.list]] specifies that overload resolution is performed
671
+ according to the rules in this subclause or when forming a
672
+ list-initialization sequence according to [[over.ics.list]], overload
673
+ resolution selects the constructor in two phases:
674
 
675
+ - If the initializer list is not empty or `T` has no default
676
+ constructor, overload resolution is first performed where the
677
+ candidate functions are the initializer-list constructors
678
+ [[dcl.init.list]] of the class `T` and the argument list consists of
679
+ the initializer list as a single argument.
680
+ - Otherwise, or if no viable initializer-list constructor is found,
681
+ overload resolution is performed again, where the candidate functions
682
+ are all the constructors of the class `T` and the argument list
683
+ consists of the elements of the initializer list.
684
 
685
+ In copy-list-initialization, if an explicit constructor is chosen, the
686
+ initialization is ill-formed.
 
687
 
688
+ [*Note 1*: This differs from other situations ([[over.match.ctor]],
689
  [[over.match.copy]]), where only converting constructors are considered
690
  for copy-initialization. This restriction only applies if this
691
  initialization is part of the final result of overload
692
  resolution. — *end note*]
693
 
694
  #### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
695
 
696
+ When resolving a placeholder for a deduced class type
697
+ [[dcl.type.class.deduct]] where the *template-name* names a primary
698
+ class template `C`, a set of functions and function templates, called
699
+ the guides of `C`, is formed comprising:
700
 
701
+ - If `C` is defined, for each constructor of `C`, a function template
702
+ with the following properties:
703
+ - The template parameters are the template parameters of `C` followed
704
+ by the template parameters (including default template arguments) of
705
+ the constructor, if any.
 
706
  - The types of the function parameters are those of the constructor.
707
  - The return type is the class template specialization designated by
708
+ `C` and template arguments corresponding to the template parameters
709
+ of `C`.
710
+ - If `C` is not defined or does not declare any constructors, an
711
+ additional function template derived as above from a hypothetical
712
+ constructor `C()`.
713
  - An additional function template derived as above from a hypothetical
714
  constructor `C(C)`, called the *copy deduction candidate*.
715
  - For each *deduction-guide*, a function or function template with the
716
  following properties:
717
  - The template parameters, if any, and function parameters are those
718
  of the *deduction-guide*.
719
  - The return type is the *simple-template-id* of the
720
  *deduction-guide*.
721
 
722
+ In addition, if `C` is defined and its definition satisfies the
723
+ conditions for an aggregate class [[dcl.init.aggr]] with the assumption
724
+ that any dependent base class has no virtual functions and no virtual
725
+ base classes, and the initializer is a non-empty *braced-init-list* or
726
+ parenthesized *expression-list*, and there are no *deduction-guide*s for
727
+ `C`, the set contains an additional function template, called the
728
+ *aggregate deduction candidate*, defined as follows. Let x₁, …, xₙ be
729
+ the elements of the *initializer-list* or *designated-initializer-list*
730
+ of the *braced-init-list*, or of the *expression-list*. For each xᵢ, let
731
+ eᵢ be the corresponding aggregate element of `C` or of one of its
732
+ (possibly recursive) subaggregates that would be initialized by xᵢ
733
+ [[dcl.init.aggr]] if
734
+
735
+ - brace elision is not considered for any aggregate element that has a
736
+ dependent non-array type or an array type with a value-dependent
737
+ bound, and
738
+ - each non-trailing aggregate element that is a pack expansion is
739
+ assumed to correspond to no elements of the initializer list, and
740
+ - a trailing aggregate element that is a pack expansion is assumed to
741
+ correspond to all remaining elements of the initializer list (if any).
742
+
743
+ If there is no such aggregate element eᵢ for any xᵢ, the aggregate
744
+ deduction candidate is not added to the set. The aggregate deduction
745
+ candidate is derived as above from a hypothetical constructor
746
+ `C`(`T₁`, …, `Tₙ`), where
747
+
748
+ - if eᵢ is of array type and xᵢ is a *braced-init-list* or
749
+ *string-literal*, `Tᵢ` is an rvalue reference to the declared type of
750
+ eᵢ, and
751
+ - otherwise, `Tᵢ` is the declared type of eᵢ,
752
+
753
+ except that additional parameter packs of the form `Pⱼ` `...` are
754
+ inserted into the parameter list in their original aggregate element
755
+ position corresponding to each non-trailing aggregate element of type
756
+ `Pⱼ` that was skipped because it was a parameter pack, and the trailing
757
+ sequence of parameters corresponding to a trailing aggregate element
758
+ that is a pack expansion (if any) is replaced by a single parameter of
759
+ the form `Tₙ` `...`.
760
+
761
+ When resolving a placeholder for a deduced class type
762
+ [[dcl.type.simple]] where the *template-name* names an alias template
763
+ `A`, the *defining-type-id* of `A` must be of the form
764
+
765
+ ``` bnf
766
+ typenameₒₚₜ nested-name-specifierₒₚₜ templateₒₚₜ simple-template-id
767
+ ```
768
+
769
+ as specified in [[dcl.type.simple]]. The guides of `A` are the set of
770
+ functions or function templates formed as follows. For each function or
771
+ function template `f` in the guides of the template named by the
772
+ *simple-template-id* of the *defining-type-id*, the template arguments
773
+ of the return type of `f` are deduced from the *defining-type-id* of `A`
774
+ according to the process in [[temp.deduct.type]] with the exception that
775
+ deduction does not fail if not all template arguments are deduced. Let
776
+ `g` denote the result of substituting these deductions into `f`. If
777
+ substitution succeeds, form a function or function template `f'` with
778
+ the following properties and add it to the set of guides of `A`:
779
+
780
+ - The function type of `f'` is the function type of `g`.
781
+ - If `f` is a function template, `f'` is a function template whose
782
+ template parameter list consists of all the template parameters of `A`
783
+ (including their default template arguments) that appear in the above
784
+ deductions or (recursively) in their default template arguments,
785
+ followed by the template parameters of `f` that were not deduced
786
+ (including their default template arguments), otherwise `f'` is not a
787
+ function template.
788
+ - The associated constraints [[temp.constr.decl]] are the conjunction of
789
+ the associated constraints of `g` and a constraint that is satisfied
790
+ if and only if the arguments of `A` are deducible (see below) from the
791
+ return type.
792
+ - If `f` is a copy deduction candidate [[over.match.class.deduct]], then
793
+ `f'` is considered to be so as well.
794
+ - If `f` was generated from a *deduction-guide*
795
+ [[over.match.class.deduct]], then `f'` is considered to be so as well.
796
+ - The *explicit-specifier* of `f'` is the *explicit-specifier* of `g`
797
+ (if any).
798
+
799
+ The arguments of a template `A` are said to be deducible from a type `T`
800
+ if, given a class template
801
+
802
+ ``` cpp
803
+ template <typename> class AA;
804
+ ```
805
+
806
+ with a single partial specialization whose template parameter list is
807
+ that of `A` and whose template argument list is a specialization of `A`
808
+ with the template argument list of `A` [[temp.dep.type]], `AA<T>`
809
+ matches the partial specialization.
810
+
811
  Initialization and overload resolution are performed as described in
812
  [[dcl.init]] and [[over.match.ctor]], [[over.match.copy]], or
813
  [[over.match.list]] (as appropriate for the type of initialization
814
+ performed) for an object of a hypothetical class type, where the guides
815
+ of the template named by the placeholder are considered to be the
816
  constructors of that class type for the purpose of forming an overload
817
  set, and the initializer is provided by the context in which class
818
+ template argument deduction was performed. The following exceptions
819
+ apply:
820
+
821
+ - The first phase in [[over.match.list]] (considering initializer-list
822
+ constructors) is omitted if the initializer list consists of a single
823
+ expression of type cv `U`, where `U` is, or is derived from, a
824
+ specialization of the class template directly or indirectly named by
825
+ the placeholder.
826
+ - During template argument deduction for the aggregate deduction
827
+ candidate, the number of elements in a trailing parameter pack is only
828
+ deduced from the number of remaining function arguments if it is not
829
+ otherwise deduced.
830
+
831
+ If the function or function template was generated from a constructor or
832
+ *deduction-guide* that had an *explicit-specifier*, each such notional
833
+ constructor is considered to have that same *explicit-specifier*. All
834
+ such notional constructors are considered to be public members of the
835
+ hypothetical class type.
836
 
837
  [*Example 1*:
838
 
839
  ``` cpp
840
  template <class T> struct A {
 
862
  template <class U> using TA = T;
863
  template <class U> B(U, TA<U>);
864
  };
865
 
866
  B b{(int*)0, (char*)0}; // OK, deduces B<char*>
867
+
868
+ template <typename T>
869
+ struct S {
870
+ T x;
871
+ T y;
872
+ };
873
+
874
+ template <typename T>
875
+ struct C {
876
+ S<T> s;
877
+ T t;
878
+ };
879
+
880
+ template <typename T>
881
+ struct D {
882
+ S<int> s;
883
+ T t;
884
+ };
885
+
886
+ C c1 = {1, 2}; // error: deduction failed
887
+ C c2 = {1, 2, 3}; // error: deduction failed
888
+ C c3 = {{1u, 2u}, 3}; // OK, deduces C<int>
889
+
890
+ D d1 = {1, 2}; // error: deduction failed
891
+ D d2 = {1, 2, 3}; // OK, braces elided, deduces D<int>
892
+
893
+ template <typename T>
894
+ struct E {
895
+ T t;
896
+ decltype(t) t2;
897
+ };
898
+
899
+ E e1 = {1, 2}; // OK, deduces E<int>
900
+
901
+ template <typename... T>
902
+ struct Types {};
903
+
904
+ template <typename... T>
905
+ struct F : Types<T...>, T... {};
906
+
907
+ struct X {};
908
+ struct Y {};
909
+ struct Z {};
910
+ struct W { operator Y(); };
911
+
912
+ F f1 = {Types<X, Y, Z>{}, {}, {}}; // OK, F<X, Y, Z> deduced
913
+ F f2 = {Types<X, Y, Z>{}, X{}, Y{}}; // OK, F<X, Y, Z> deduced
914
+ F f3 = {Types<X, Y, Z>{}, X{}, W{}}; // error: conflicting types deduced; operator Y not considered
915
+ ```
916
+
917
+ — *end example*]
918
+
919
+ [*Example 2*:
920
+
921
+ ``` cpp
922
+ template <class T, class U> struct C {
923
+ C(T, U); // #1
924
+ };
925
+ template<class T, class U>
926
+ C(T, U) -> C<T, std::type_identity_t<U>>; // #2
927
+
928
+ template<class V> using A = C<V *, V *>;
929
+ template<std::integral W> using B = A<W>;
930
+
931
+ int i{};
932
+ double d{};
933
+ A a1(&i, &i); // deduces A<int>
934
+ A a2(i, i); // error: cannot deduce V * from i
935
+ A a3(&i, &d); // error: #1: cannot deduce (V*, V*) from (int *, double *)
936
+ // #2: cannot deduce A<V> from C<int *, double *>
937
+ B b1(&i, &i); // deduces B<int>
938
+ B b2(&d, &d); // error: cannot deduce B<W> from C<double *, double *>
939
+ ```
940
+
941
+ Possible exposition-only implementation of the above procedure:
942
+
943
+ ``` cpp
944
+ // The following concept ensures a specialization of A is deduced.
945
+ template <class> class AA;
946
+ template <class V> class AA<A<V>> { };
947
+ template <class T> concept deduces_A = requires { sizeof(AA<T>); };
948
+
949
+ // f1 is formed from the constructor #1 of C, generating the following function template
950
+ template<T, U>
951
+ auto f1(T, U) -> C<T, U>;
952
+
953
+ // Deducing arguments for C<T, U> from C<V *, V*> deduces T as V * and U as V *;
954
+ // f1' is obtained by transforming f1 as described by the above procedure.
955
+ template<class V> requires deduces_A<C<V *, V *>>
956
+ auto f1_prime(V *, V*) -> C<V *, V *>;
957
+
958
+ // f2 is formed from the deduction-guide #2 of C
959
+ template<class T, class U> auto f2(T, U) -> C<T, std::type_identity_t<U>>;
960
+
961
+ // Deducing arguments for C<T, std::type_identity_t<U>> from C<V *, V*> deduces T as V *;
962
+ // f2' is obtained by transforming f2 as described by the above procedure.
963
+ template<class V, class U>
964
+ requires deduces_A<C<V *, std::type_identity_t<U>>>
965
+ auto f2_prime(V *, U) -> C<V *, std::type_identity_t<U>>;
966
+
967
+ // The following concept ensures a specialization of B is deduced.
968
+ template <class> class BB;
969
+ template <class V> class BB<B<V>> { };
970
+ template <class T> concept deduces_B = requires { sizeof(BB<T>); };
971
+
972
+ // The guides for B derived from the above f1' and f2' for A are as follows:
973
+ template<std::integral W>
974
+ requires deduces_A<C<W *, W *>> && deduces_B<C<W *, W *>>
975
+ auto f1_prime_for_B(W *, W *) -> C<W *, W *>;
976
+
977
+ template<std::integral W, class U>
978
+ requires deduces_A<C<W *, std::type_identity_t<U>>> &&
979
+ deduces_B<C<W *, std::type_identity_t<U>>>
980
+ auto f2_prime_for_B(W *, U) -> C<W *, std::type_identity_t<U>>;
981
  ```
982
 
983
  — *end example*]
984
 
985
  ### Viable functions <a id="over.match.viable">[[over.match.viable]]</a>
986
 
987
+ From the set of candidate functions constructed for a given context
988
+ [[over.match.funcs]], a set of viable functions is chosen, from which
989
  the best function will be selected by comparing argument conversion
990
+ sequences and associated constraints [[temp.constr.decl]] for the best
991
+ fit [[over.match.best]]. The selection of viable functions considers
992
+ associated constraints, if any, and relationships between arguments and
993
+ function parameters other than the ranking of conversion sequences.
994
 
995
  First, to be a viable function, a candidate function shall have enough
996
  parameters to agree in number with the arguments in the list.
997
 
998
  - If there are *m* arguments in the list, all candidate functions having
999
  exactly *m* parameters are viable.
1000
  - A candidate function having fewer than *m* parameters is viable only
1001
+ if it has an ellipsis in its parameter list [[dcl.fct]]. For the
1002
  purposes of overload resolution, any argument for which there is no
1003
+ corresponding parameter is considered to “match the ellipsis”
1004
+ [[over.ics.ellipsis]] .
1005
  - A candidate function having more than *m* parameters is viable only if
1006
+ all parameters following the mᵗʰ have default arguments
1007
+ [[dcl.fct.default]]. For the purposes of overload resolution, the
1008
  parameter list is truncated on the right, so that there are exactly
1009
  *m* parameters.
1010
 
1011
+ Second, for a function to be viable, if it has associated constraints
1012
+ [[temp.constr.decl]], those constraints shall be satisfied
1013
+ [[temp.constr.constr]].
1014
+
1015
+ Third, for `F` to be a viable function, there shall exist for each
1016
+ argument an implicit conversion sequence [[over.best.ics]] that converts
1017
+ that argument to the corresponding parameter of `F`. If the parameter
1018
+ has reference type, the implicit conversion sequence includes the
1019
+ operation of binding the reference, and the fact that an lvalue
1020
  reference to non-`const` cannot be bound to an rvalue and that an rvalue
1021
  reference cannot be bound to an lvalue can affect the viability of the
1022
  function (see  [[over.ics.ref]]).
1023
 
1024
  ### Best viable function <a id="over.match.best">[[over.match.best]]</a>
 
1026
  Define ICS*i*(`F`) as follows:
1027
 
1028
  - If `F` is a static member function, ICS*1*(`F`) is defined such that
1029
  ICS*1*(`F`) is neither better nor worse than ICS*1*(`G`) for any
1030
  function `G`, and, symmetrically, ICS*1*(`G`) is neither better nor
1031
+ worse than ICS*1*(`F`);[^8] otherwise,
1032
  - let ICS*i*(`F`) denote the implicit conversion sequence that converts
1033
  the *i*-th argument in the list to the type of the *i*-th parameter of
1034
  viable function `F`. [[over.best.ics]] defines the implicit conversion
1035
  sequences and [[over.ics.rank]] defines what it means for one implicit
1036
  conversion sequence to be a better conversion sequence or worse
 
1063
  ```
1064
 
1065
  — *end example*]
1066
  or, if not that,
1067
  - the context is an initialization by conversion function for direct
1068
+ reference binding [[over.match.ref]] of a reference to function type,
1069
+ the return type of `F1` is the same kind of reference (lvalue or
1070
+ rvalue) as the reference being initialized, and the return type of
1071
+ `F2` is not
1072
  \[*Example 2*:
1073
  ``` cpp
1074
  template <class T> struct A {
1075
  operator T&(); // #1
1076
  operator T&&(); // #2
 
1087
  template specialization, or, if not that,
1088
  - `F1` and `F2` are function template specializations, and the function
1089
  template for `F1` is more specialized than the template for `F2`
1090
  according to the partial ordering rules described in 
1091
  [[temp.func.order]], or, if not that,
1092
+ - `F1` and `F2` are non-template functions with the same
1093
+ parameter-type-lists, and `F1` is more constrained than `F2` according
1094
+ to the partial ordering of constraints described in
1095
+ [[temp.constr.order]], or if not that,
1096
+ - `F1` is a constructor for a class `D`, `F2` is a constructor for a
1097
+ base class `B` of `D`, and for all arguments the corresponding
1098
+ parameters of `F1` and `F2` have the same type.
1099
+ \[*Example 3*:
1100
+ ``` cpp
1101
+ struct A {
1102
+ A(int = 0);
1103
+ };
1104
+
1105
+ struct B: A {
1106
+ using A::A;
1107
+ B();
1108
+ };
1109
+
1110
+ int main() {
1111
+ B b; // OK, B::B()
1112
+ }
1113
+ ```
1114
+
1115
+ — *end example*]
1116
+ or, if not that,
1117
+ - `F2` is a rewritten candidate [[over.match.oper]] and `F1` is not
1118
+ \[*Example 4*:
1119
+ ``` cpp
1120
+ struct S {
1121
+ friend auto operator<=>(const S&, const S&) = default; // #1
1122
+ friend bool operator<(const S&, const S&); // #2
1123
+ };
1124
+ bool b = S() < S(); // calls #2
1125
+ ```
1126
+
1127
+ — *end example*]
1128
+ or, if not that,
1129
+ - `F1` and `F2` are rewritten candidates, and `F2` is a synthesized
1130
+ candidate with reversed order of parameters and `F1` is not
1131
+ \[*Example 5*:
1132
+ ``` cpp
1133
+ struct S {
1134
+ friend std::weak_ordering operator<=>(const S&, int); // #1
1135
+ friend std::weak_ordering operator<=>(int, const S&); // #2
1136
+ };
1137
+ bool b = 1 < S(); // calls #2
1138
+ ```
1139
+
1140
+ — *end example*]
1141
+ or, if not that
1142
+ - `F1` is generated from a *deduction-guide* [[over.match.class.deduct]]
1143
  and `F2` is not, or, if not that,
1144
+ - `F1` is the copy deduction candidate [[over.match.class.deduct]] and
1145
+ `F2` is not, or, if not that,
1146
  - `F1` is generated from a non-template constructor and `F2` is
1147
  generated from a constructor template.
1148
+ \[*Example 6*:
1149
  ``` cpp
1150
  template <class T> struct A {
1151
  using value_type = T;
1152
  A(value_type); // #1
1153
  A(const A&); // #2
 
1173
 
1174
  — *end example*]
1175
 
1176
  If there is exactly one viable function that is a better function than
1177
  all other viable functions, then it is the one selected by overload
1178
+ resolution; otherwise the call is ill-formed.[^9]
1179
 
1180
+ [*Example 7*:
1181
 
1182
  ``` cpp
1183
  void Fcn(const int*, short);
1184
  void Fcn(int*, int);
1185
 
 
1204
  declarations were found, and if at least two of these declarations — or
1205
  the declarations they refer to in the case of *using-declaration*s —
1206
  specify a default argument that made the function viable, the program is
1207
  ill-formed.
1208
 
1209
+ [*Example 8*:
1210
 
1211
  ``` cpp
1212
  namespace A {
1213
  extern "C" void f(int = 5);
1214
  }
 
1219
  using A::f;
1220
  using B::f;
1221
 
1222
  void use() {
1223
  f(3); // OK, default argument was not used for viability
1224
+ f(); // error: found default argument twice
1225
  }
1226
  ```
1227
 
1228
  — *end example*]
1229
 
1230
  #### Implicit conversion sequences <a id="over.best.ics">[[over.best.ics]]</a>
1231
 
1232
  An *implicit conversion sequence* is a sequence of conversions used to
1233
  convert an argument in a function call to the type of the corresponding
1234
  parameter of the function being called. The sequence of conversions is
1235
+ an implicit conversion as defined in [[conv]], which means it is
1236
  governed by the rules for initialization of an object or reference by a
1237
  single expression ([[dcl.init]], [[dcl.init.ref]]).
1238
 
1239
  Implicit conversion sequences are concerned only with the type,
1240
  cv-qualification, and value category of the argument and how these are
1241
+ converted to match the corresponding properties of the parameter.
1242
+
1243
+ [*Note 1*: Other properties, such as the lifetime, storage class,
1244
+ alignment, accessibility of the argument, whether the argument is a
1245
+ bit-field, and whether a function is deleted [[dcl.fct.def.delete]], are
1246
+ ignored. So, although an implicit conversion sequence can be defined for
1247
+ a given argument-parameter pair, the conversion from the argument to the
1248
+ parameter might still be ill-formed in the final
1249
+ analysis. — *end note*]
1250
 
1251
  A well-formed implicit conversion sequence is one of the following
1252
  forms:
1253
 
1254
+ - a standard conversion sequence [[over.ics.scs]],
1255
+ - a user-defined conversion sequence [[over.ics.user]], or
1256
+ - an ellipsis conversion sequence [[over.ics.ellipsis]].
1257
 
1258
  However, if the target is
1259
 
1260
  - the first parameter of a constructor or
1261
  - the implicit object parameter of a user-defined conversion function
 
1272
  is the first parameter of a constructor of class `X`, and the
1273
  conversion is to `X` or reference to cv `X`,
1274
 
1275
  user-defined conversion sequences are not considered.
1276
 
1277
+ [*Note 2*: These rules prevent more than one user-defined conversion
1278
  from being applied during overload resolution, thereby avoiding infinite
1279
  recursion. — *end note*]
1280
 
1281
  [*Example 1*:
1282
 
1283
  ``` cpp
1284
  struct Y { Y(int); };
1285
  struct A { operator int(); };
1286
  Y y1 = A(); // error: A::operator int() is not a candidate
1287
 
1288
+ struct X { X(); };
1289
  struct B { operator X(); };
1290
  B b;
1291
+ X x{{b}}; // error: B::operator X() is not a candidate
1292
  ```
1293
 
1294
  — *end example*]
1295
 
1296
  For the case where the parameter type is a reference, see 
 
1300
  sequence models a copy-initialization of the parameter from the argument
1301
  expression. The implicit conversion sequence is the one required to
1302
  convert the argument expression to a prvalue of the type of the
1303
  parameter.
1304
 
1305
+ [*Note 3*: When the parameter has a class type, this is a conceptual
1306
+ conversion defined for the purposes of [[over]]; the actual
1307
  initialization is defined in terms of constructors and is not a
1308
  conversion. — *end note*]
1309
 
1310
  Any difference in top-level cv-qualification is subsumed by the
1311
  initialization itself and does not constitute a conversion.
 
1317
 
1318
  When the parameter has a class type and the argument expression has the
1319
  same type, the implicit conversion sequence is an identity conversion.
1320
  When the parameter has a class type and the argument expression has a
1321
  derived class type, the implicit conversion sequence is a
1322
+ derived-to-base conversion from the derived class to the base class.
1323
 
1324
+ [*Note 4*: There is no such standard conversion; this derived-to-base
1325
+ conversion exists only in the description of implicit conversion
1326
  sequences. — *end note*]
1327
 
1328
+ A derived-to-base conversion has Conversion rank [[over.ics.scs]].
1329
 
1330
  In all contexts, when converting to the implicit object parameter or
1331
  when converting to the left operand of an assignment operation only
1332
  standard conversion sequences are allowed.
1333
 
1334
  If no conversions are required to match an argument to a parameter type,
1335
  the implicit conversion sequence is the standard conversion sequence
1336
+ consisting of the identity conversion [[over.ics.scs]].
1337
 
1338
  If no sequence of conversions can be found to convert an argument to a
1339
  parameter type, an implicit conversion sequence cannot be formed.
1340
 
1341
+ If there are multiple well-formed implicit conversion sequences
1342
+ converting the argument to the parameter type, the implicit conversion
1343
+ sequence associated with the parameter is defined to be the unique
1344
+ conversion sequence designated the *ambiguous conversion sequence*. For
1345
+ the purpose of ranking implicit conversion sequences as described in 
1346
  [[over.ics.rank]], the ambiguous conversion sequence is treated as a
1347
  user-defined conversion sequence that is indistinguishable from any
1348
  other user-defined conversion sequence.
1349
 
1350
+ [*Note 5*:
1351
 
1352
  This rule prevents a function from becoming non-viable because of an
1353
  ambiguous conversion sequence for one of its parameters.
1354
 
1355
  [*Example 3*:
 
1360
  class B { operator A (); };
1361
  class C { C (B&); };
1362
  void f(A) { }
1363
  void f(C) { }
1364
  B b;
1365
+ f(b); // error: ambiguous because there is a conversion b → C (via constructor)
1366
  // and an (ambiguous) conversion b → A (via constructor or conversion function)
1367
  void f(B) { }
1368
  f(b); // OK, unambiguous
1369
  ```
1370
 
 
1379
  The three forms of implicit conversion sequences mentioned above are
1380
  defined in the following subclauses.
1381
 
1382
  ##### Standard conversion sequences <a id="over.ics.scs">[[over.ics.scs]]</a>
1383
 
1384
+ summarizes the conversions defined in [[conv]] and partitions them into
1385
+ four disjoint categories: Lvalue Transformation, Qualification
1386
+ Adjustment, Promotion, and Conversion.
 
1387
 
1388
+ [*Note 6*: These categories are orthogonal with respect to value
1389
  category, cv-qualification, and data representation: the Lvalue
1390
  Transformations do not change the cv-qualification or data
1391
  representation of the type; the Qualification Adjustments do not change
1392
  the value category or data representation of the type; and the
1393
  Promotions and Conversions do not change the value category or
1394
  cv-qualification of the type. — *end note*]
1395
 
1396
+ [*Note 7*: As described in [[conv]], a standard conversion sequence
1397
+ either is the Identity conversion by itself (that is, no conversion) or
1398
+ consists of one to three conversions from the other four categories. If
1399
+ there are two or more conversions in the sequence, the conversions are
1400
+ applied in the canonical order: **Lvalue Transformation**, **Promotion**
1401
+ or **Conversion**, **Qualification Adjustment**. *end note*]
 
1402
 
1403
+ Each conversion in [[over.ics.scs]] also has an associated rank (Exact
1404
+ Match, Promotion, or Conversion). These are used to rank standard
1405
+ conversion sequences [[over.ics.rank]]. The rank of a conversion
1406
+ sequence is determined by considering the rank of each conversion in the
1407
+ sequence and the rank of any reference binding [[over.ics.ref]]. If any
1408
+ of those has Conversion rank, the sequence has Conversion rank;
1409
+ otherwise, if any of those has Promotion rank, the sequence has
1410
+ Promotion rank; otherwise, the sequence has Exact Match rank.
 
1411
 
1412
+ **Table: Conversions** <a id="over.ics.scs">[over.ics.scs]</a>
1413
 
1414
  | Conversion | Category | Rank | Subclause |
1415
  | ----------------------- | -------- | ---- | ----------------- |
1416
  | No conversions required | Identity | | |
1417
  | Integral promotions | | | [[conv.prom]] |
1418
  | Integral conversions | | | [[conv.integral]] |
1419
 
1420
 
1421
  ##### User-defined conversion sequences <a id="over.ics.user">[[over.ics.user]]</a>
1422
 
1423
+ A *user-defined conversion sequence* consists of an initial standard
1424
+ conversion sequence followed by a user-defined conversion [[class.conv]]
1425
+ followed by a second standard conversion sequence. If the user-defined
1426
+ conversion is specified by a constructor [[class.conv.ctor]], the
1427
+ initial standard conversion sequence converts the source type to the
1428
+ type required by the argument of the constructor. If the user-defined
1429
+ conversion is specified by a conversion function [[class.conv.fct]], the
1430
+ initial standard conversion sequence converts the source type to the
1431
+ implicit object parameter of the conversion function.
 
1432
 
1433
  The second standard conversion sequence converts the result of the
1434
+ user-defined conversion to the target type for the sequence; any
1435
+ reference binding is included in the second standard conversion
1436
+ sequence. Since an implicit conversion sequence is an initialization,
1437
+ the special rules for initialization by user-defined conversion apply
1438
+ when selecting the best user-defined conversion for a user-defined
1439
+ conversion sequence (see  [[over.match.best]] and  [[over.best.ics]]).
1440
 
1441
  If the user-defined conversion is specified by a specialization of a
1442
  conversion function template, the second standard conversion sequence
1443
  shall have exact match rank.
1444
 
 
1454
  call is matched with the ellipsis parameter specification of the
1455
  function called (see  [[expr.call]]).
1456
 
1457
  ##### Reference binding <a id="over.ics.ref">[[over.ics.ref]]</a>
1458
 
1459
+ When a parameter of reference type binds directly [[dcl.init.ref]] to an
1460
+ argument expression, the implicit conversion sequence is the identity
1461
  conversion, unless the argument expression has a type that is a derived
1462
  class of the parameter type, in which case the implicit conversion
1463
+ sequence is a derived-to-base Conversion [[over.best.ics]].
1464
 
1465
  [*Example 4*:
1466
 
1467
  ``` cpp
1468
  struct A {};
 
1474
 
1475
  — *end example*]
1476
 
1477
  If the parameter binds directly to the result of applying a conversion
1478
  function to the argument expression, the implicit conversion sequence is
1479
+ a user-defined conversion sequence [[over.ics.user]], with the second
1480
  standard conversion sequence either an identity conversion or, if the
1481
  conversion function returns an entity of a type that is a derived class
1482
+ of the parameter type, a derived-to-base conversion.
1483
 
1484
  When a parameter of reference type is not bound directly to an argument
1485
  expression, the conversion sequence is the one required to convert the
1486
  argument expression to the referenced type according to 
1487
  [[over.best.ics]]. Conceptually, this conversion sequence corresponds to
1488
  copy-initializing a temporary of the referenced type with the argument
1489
  expression. Any difference in top-level cv-qualification is subsumed by
1490
  the initialization itself and does not constitute a conversion.
1491
 
1492
  Except for an implicit object parameter, for which see 
1493
+ [[over.match.funcs]], an implicit conversion sequence cannot be formed
1494
+ if it requires binding an lvalue reference other than a reference to a
1495
  non-volatile `const` type to an rvalue or binding an rvalue reference to
1496
  an lvalue other than a function lvalue.
1497
 
1498
+ [*Note 8*: This means, for example, that a candidate function cannot be
1499
  a viable function if it has a non-`const` lvalue reference parameter
1500
  (other than the implicit object parameter) and the corresponding
1501
  argument would require a temporary to be created to initialize the
1502
  lvalue reference (see  [[dcl.init.ref]]). — *end note*]
1503
 
1504
  Other restrictions on binding a reference to a particular argument that
1505
  are not based on the types of the reference and the argument do not
1506
+ affect the formation of an implicit conversion sequence, however.
1507
 
1508
  [*Example 5*: A function with an “lvalue reference to `int`” parameter
1509
  can be a viable candidate even if the corresponding argument is an `int`
1510
  bit-field. The formation of implicit conversion sequences treats the
1511
  `int` bit-field as an `int` lvalue and finds an exact match with the
1512
  parameter. If the function is selected by overload resolution, the call
1513
  will nonetheless be ill-formed because of the prohibition on binding a
1514
+ non-`const` lvalue reference to a bit-field
1515
+ [[dcl.init.ref]]. — *end example*]
1516
 
1517
  ##### List-initialization sequence <a id="over.ics.list">[[over.ics.list]]</a>
1518
 
1519
+ When an argument is an initializer list [[dcl.init.list]], it is not an
1520
+ expression and special rules apply for converting it to a parameter
1521
  type.
1522
 
1523
+ If the initializer list is a *designated-initializer-list*, a conversion
1524
+ is only possible if the parameter has an aggregate type that can be
1525
+ initialized from the initializer list according to the rules for
1526
+ aggregate initialization [[dcl.init.aggr]], in which case the implicit
1527
+ conversion sequence is a user-defined conversion sequence whose second
1528
+ standard conversion sequence is an identity conversion.
1529
 
1530
+ [*Note 9*:
1531
+
1532
+ Aggregate initialization does not require that the members are declared
1533
+ in designation order. If, after overload resolution, the order does not
1534
+ match for the selected overload, the initialization of the parameter
1535
+ will be ill-formed [[dcl.init.list]].
1536
+
1537
+ [*Example 6*:
1538
+
1539
+ ``` cpp
1540
+ struct A { int x, y; };
1541
+ struct B { int y, x; };
1542
+ void f(A a, int); // #1
1543
+ void f(B b, ...); // #2
1544
+ void g(A a); // #3
1545
+ void g(B b); // #4
1546
+ void h() {
1547
+ f({.x = 1, .y = 2}, 0); // OK; calls #1
1548
+ f({.y = 2, .x = 1}, 0); // error: selects #1, initialization of a fails
1549
+ // due to non-matching member order[dcl.init.list]
1550
+ g({.x = 1, .y = 2}); // error: ambiguous between #3 and #4
1551
+ }
1552
+ ```
1553
+
1554
+ — *end example*]
1555
+
1556
+ — *end note*]
1557
+
1558
+ Otherwise, if the parameter type is an aggregate class `X` and the
1559
+ initializer list has a single element of type cv `U`, where `U` is `X`
1560
+ or a class derived from `X`, the implicit conversion sequence is the one
1561
+ required to convert the element to the parameter type.
1562
+
1563
+ Otherwise, if the parameter type is a character array [^10] and the
1564
  initializer list has a single element that is an appropriately-typed
1565
+ *string-literal* [[dcl.init.string]], the implicit conversion sequence
1566
  is the identity conversion.
1567
 
1568
  Otherwise, if the parameter type is `std::initializer_list<X>` and all
1569
  the elements of the initializer list can be implicitly converted to `X`,
1570
  the implicit conversion sequence is the worst conversion necessary to
1571
  convert an element of the list to `X`, or if the initializer list has no
1572
  elements, the identity conversion. This conversion can be a user-defined
1573
  conversion even in the context of a call to an initializer-list
1574
  constructor.
1575
 
1576
+ [*Example 7*:
1577
 
1578
  ``` cpp
1579
  void f(std::initializer_list<int>);
1580
  f( {} ); // OK: f(initializer_list<int>) identity conversion
1581
  f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
 
1597
  h({ 1, 2, 3 }); // OK: identity conversion
1598
  ```
1599
 
1600
  — *end example*]
1601
 
1602
+ Otherwise, if the parameter type is “array of `N` `X`” or “array of
1603
+ unknown bound of `X`”, if there exists an implicit conversion sequence
1604
+ from each element of the initializer list (and from `{}` in the former
1605
+ case if `N` exceeds the number of elements in the initializer list) to
1606
+ `X`, the implicit conversion sequence is the worst such implicit
1607
+ conversion sequence.
1608
 
1609
  Otherwise, if the parameter is a non-aggregate class `X` and overload
1610
  resolution per  [[over.match.list]] chooses a single best constructor
1611
  `C` of `X` to perform the initialization of an object of type `X` from
1612
  the argument initializer list:
 
1623
  the implicit conversion sequence is the ambiguous conversion sequence.
1624
  User-defined conversions are allowed for conversion of the initializer
1625
  list elements to the constructor parameter types except as noted in 
1626
  [[over.best.ics]].
1627
 
1628
+ [*Example 8*:
1629
 
1630
  ``` cpp
1631
  struct A {
1632
  A(std::initializer_list<int>);
1633
  };
 
1659
 
1660
  — *end example*]
1661
 
1662
  Otherwise, if the parameter has an aggregate type which can be
1663
  initialized from the initializer list according to the rules for
1664
+ aggregate initialization [[dcl.init.aggr]], the implicit conversion
1665
  sequence is a user-defined conversion sequence with the second standard
1666
  conversion sequence an identity conversion.
1667
 
1668
+ [*Example 9*:
1669
 
1670
  ``` cpp
1671
  struct A {
1672
  int m1;
1673
  double m2;
 
1680
 
1681
  — *end example*]
1682
 
1683
  Otherwise, if the parameter is a reference, see  [[over.ics.ref]].
1684
 
1685
+ [*Note 10*: The rules in this subclause will apply for initializing the
1686
  underlying temporary for the reference. — *end note*]
1687
 
1688
+ [*Example 10*:
1689
 
1690
  ``` cpp
1691
  struct A {
1692
  int m1;
1693
  double m2;
 
1706
  Otherwise, if the parameter type is not a class:
1707
 
1708
  - if the initializer list has one element that is not itself an
1709
  initializer list, the implicit conversion sequence is the one required
1710
  to convert the element to the parameter type;
1711
+ \[*Example 11*:
1712
  ``` cpp
1713
  void f(int);
1714
  f( {'a'} ); // OK: same conversion as char to int
1715
  f( {1.0} ); // error: narrowing
1716
  ```
1717
 
1718
  — *end example*]
1719
  - if the initializer list has no elements, the implicit conversion
1720
  sequence is the identity conversion.
1721
+ \[*Example 12*:
1722
  ``` cpp
1723
  void f(int);
1724
  f( { } ); // OK: identity conversion
1725
  ```
1726
 
 
1740
  S2, S1 and S2 are said to be *indistinguishable conversion sequences*.
1741
 
1742
  When comparing the basic forms of implicit conversion sequences (as
1743
  defined in  [[over.best.ics]])
1744
 
1745
+ - a standard conversion sequence [[over.ics.scs]] is a better conversion
1746
+ sequence than a user-defined conversion sequence or an ellipsis
1747
+ conversion sequence, and
1748
+ - a user-defined conversion sequence [[over.ics.user]] is a better
1749
+ conversion sequence than an ellipsis conversion sequence
1750
+ [[over.ics.ellipsis]].
1751
 
1752
  Two implicit conversion sequences of the same form are indistinguishable
1753
  conversion sequences unless one of the following rules applies:
1754
 
1755
  - List-initialization sequence `L1` is a better conversion sequence than
1756
  list-initialization sequence `L2` if
1757
  - `L1` converts to `std::initializer_list<X>` for some `X` and `L2`
1758
  does not, or, if not that,
1759
+ - `L1` and `L2` convert to arrays of the same element type, and either
1760
+ the number of elements n₁ initialized by `L1` is less than the
1761
+ number of elements n₂ initialized by `L2`, or n₁ = n₂ and `L2`
1762
+ converts to an array of unknown bound and `L1` does not,
1763
 
1764
  even if one of the other rules in this paragraph would otherwise
1765
  apply.
1766
  \[*Example 1*:
1767
  ``` cpp
 
1772
  void f2(std::pair<const char*, const char*>); // #3
1773
  void f2(std::initializer_list<std::string>); // #4
1774
  void g2() { f2({"foo","bar"}); } // chooses #4
1775
  ```
1776
 
1777
+ — *end example*]
1778
+ \[*Example 2*:
1779
+ ``` cpp
1780
+ void f(int (&&)[] ); // #1
1781
+ void f(double (&&)[] ); // #2
1782
+ void f(int (&&)[2]); // #3
1783
+
1784
+ f( {1} ); // Calls #1: Better than #2 due to conversion, better than #3 due to bounds
1785
+ f( {1.0} ); // Calls #2: Identity conversion is better than floating-integral conversion
1786
+ f( {1.0, 2.0} ); // Calls #2: Identity conversion is better than floating-integral conversion
1787
+ f( {1, 2} ); // Calls #3: Converting to array of known bound is better than to unknown bound,
1788
+ // and an identity conversion is better than floating-integral conversion
1789
+ ```
1790
+
1791
  — *end example*]
1792
  - Standard conversion sequence `S1` is a better conversion sequence than
1793
  standard conversion sequence `S2` if
1794
  - `S1` is a proper subsequence of `S2` (comparing the conversion
1795
  sequences in the canonical form defined by  [[over.ics.scs]],
 
1797
  sequence is considered to be a subsequence of any non-identity
1798
  conversion sequence) or, if not that,
1799
  - the rank of `S1` is better than the rank of `S2`, or `S1` and `S2`
1800
  have the same rank and are distinguishable by the rules in the
1801
  paragraph below, or, if not that,
1802
+ - `S1` and `S2` include reference bindings [[dcl.init.ref]] and
1803
+ neither refers to an implicit object parameter of a non-static
1804
+ member function declared without a *ref-qualifier*, and `S1` binds
1805
+ an rvalue reference to an rvalue and `S2` binds an lvalue reference
1806
+ \[*Example 3*:
1807
  ``` cpp
1808
  int i;
1809
  int f1();
1810
  int&& f2();
1811
  int g(const int&);
 
1829
  a.p(); // calls A::p()&
1830
  ```
1831
 
1832
  — *end example*]
1833
  or, if not that,
1834
+ - `S1` and `S2` include reference bindings [[dcl.init.ref]] and `S1`
1835
  binds an lvalue reference to a function lvalue and `S2` binds an
1836
  rvalue reference to a function lvalue
1837
+ \[*Example 4*:
1838
  ``` cpp
1839
  int f(void(&)()); // #1
1840
  int f(void(&&)()); // #2
1841
  void g();
1842
  int i1 = f(g); // calls #1
1843
  ```
1844
 
1845
  — *end example*]
1846
  or, if not that,
1847
+ - `S1` and `S2` differ only in their qualification conversion
1848
+ [[conv.qual]] and yield similar types `T1` and `T2`, respectively,
1849
+ where `T1` can be converted to `T2` by a qualification conversion.
1850
+ \[*Example 5*:
 
 
1851
  ``` cpp
1852
  int f(const volatile int *);
1853
  int f(const int *);
1854
  int i;
1855
  int j = f(&i); // calls f(const int*)
1856
  ```
1857
 
1858
  — *end example*]
1859
  or, if not that,
1860
  - `S1`
1861
+ and `S2` include reference bindings [[dcl.init.ref]], and the types
1862
  to which the references refer are the same type except for top-level
1863
  cv-qualifiers, and the type to which the reference initialized by
1864
  `S2` refers is more cv-qualified than the type to which the
1865
  reference initialized by `S1` refers.
1866
+ \[*Example 6*:
1867
  ``` cpp
1868
  int f(const int &);
1869
  int f(int &);
1870
  int g(const int &);
1871
  int g(int);
 
1889
  than another user-defined conversion sequence `U2` if they contain the
1890
  same user-defined conversion function or constructor or they
1891
  initialize the same class in an aggregate initialization and in either
1892
  case the second standard conversion sequence of `U1` is better than
1893
  the second standard conversion sequence of `U2`.
1894
+ \[*Example 7*:
1895
  ``` cpp
1896
  struct A {
1897
  operator short();
1898
  } a;
1899
  int f(int);
 
1907
  Standard conversion sequences are ordered by their ranks: an Exact Match
1908
  is a better conversion than a Promotion, which is a better conversion
1909
  than a Conversion. Two conversion sequences with the same rank are
1910
  indistinguishable unless one of the following rules applies:
1911
 
1912
+ - A conversion that does not convert a pointer or a pointer to member to
1913
+ `bool` is better than one that does.
1914
  - A conversion that promotes an enumeration whose underlying type is
1915
  fixed to its underlying type is better than one that promotes to the
1916
  promoted underlying type, if the two are different.
1917
  - If class `B` is derived directly or indirectly from class `A`,
1918
  conversion of `B*` to `A*` is better than conversion of `B*` to
 
1920
  of `B*` to `void*`.
1921
  - If class `B` is derived directly or indirectly from class `A` and
1922
  class `C` is derived directly or indirectly from `B`,
1923
  - conversion of `C*` to `B*` is better than conversion of `C*` to
1924
  `A*`,
1925
+ \[*Example 8*:
1926
  ``` cpp
1927
  struct A {};
1928
  struct B : public A {};
1929
  struct C : public B {};
1930
  C* pc;