From Jason Turner

[over.match.funcs]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpbt0t7tiv/{from.md → to.md} +373 -191
tmp/tmpbt0t7tiv/{from.md → to.md} RENAMED
@@ -1,28 +1,33 @@
1
  ### Candidate functions and argument lists <a id="over.match.funcs">[[over.match.funcs]]</a>
2
 
 
 
3
  The subclauses of  [[over.match.funcs]] describe the set of candidate
4
  functions and the argument list submitted to overload resolution in each
5
  context in which overload resolution is used. The source transformations
6
  and constructions defined in these subclauses are only for the purpose
7
  of describing the overload resolution process. An implementation is not
8
  required to use such transformations and constructions.
9
 
10
  The set of candidate functions can contain both member and non-member
11
- functions to be resolved against the same argument list. So that
12
- argument and parameter lists are comparable within this heterogeneous
13
- set, a member function is considered to have an extra first parameter,
14
- called the *implicit object parameter*, which represents the object for
15
- which the member function has been called. For the purposes of overload
16
- resolution, both static and non-static member functions have an implicit
17
- object parameter, but constructors do not.
 
 
 
18
 
19
  Similarly, when appropriate, the context can construct an argument list
20
  that contains an *implied object argument* as the first argument in the
21
  list to denote the object to be operated on.
22
 
23
- For non-static member functions, the type of the implicit object
24
  parameter is
25
 
26
  - “lvalue reference to cv `X`” for functions declared without a
27
  *ref-qualifier* or with the `&` *ref-qualifier*
28
  - “rvalue reference to cv `X`” for functions declared with the `&&`
@@ -30,44 +35,46 @@ parameter is
30
 
31
  where `X` is the class of which the function is a member and cv is the
32
  cv-qualification on the member function declaration.
33
 
34
  [*Example 1*: For a `const` member function of class `X`, the extra
35
- parameter is assumed to have type “reference to
36
  `const X`”. — *end example*]
37
 
38
- For conversion functions, the function is considered to be a member of
39
- the class of the implied object argument for the purpose of defining the
40
- type of the implicit object parameter. For non-conversion functions
41
- introduced by a *using-declaration* into a derived class, the function
42
- is considered to be a member of the derived class for the purpose of
43
- defining the type of the implicit object parameter. For static member
44
- functions, the implicit object parameter is considered to match any
45
- object (since if the function is selected, the object is discarded).
 
 
46
 
47
  [*Note 1*: No actual type is established for the implicit object
48
  parameter of a static member function, and no attempt will be made to
49
  determine a conversion sequence for that parameter
50
  [[over.match.best]]. — *end note*]
51
 
52
  During overload resolution, the implied object argument is
53
  indistinguishable from other arguments. The implicit object parameter,
54
  however, retains its identity since no user-defined conversions can be
55
- applied to achieve a type match with it. For non-static member functions
56
- declared without a *ref-qualifier*, even if the implicit object
57
- parameter is not const-qualified, an rvalue can be bound to the
58
  parameter as long as in all other respects the argument can be converted
59
  to the type of the implicit object parameter.
60
 
61
  [*Note 2*: The fact that such an argument is an rvalue does not affect
62
  the ranking of implicit conversion sequences
63
  [[over.ics.rank]]. — *end note*]
64
 
65
  Because other than in list-initialization only one user-defined
66
  conversion is allowed in an implicit conversion sequence, special rules
67
- apply when selecting the best user-defined conversion (
68
- [[over.match.best]], [[over.best.ics]]).
69
 
70
  [*Example 2*:
71
 
72
  ``` cpp
73
  class T {
@@ -82,33 +89,57 @@ public:
82
  T a = 1; // error: no viable conversion (T(C(1)) not considered)
83
  ```
84
 
85
  — *end example*]
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  In each case where a candidate is a function template, candidate
88
  function template specializations are generated using template argument
89
- deduction ([[temp.over]], [[temp.deduct]]). If a constructor template
90
- or conversion function template has an *explicit-specifier* whose
91
  *constant-expression* is value-dependent [[temp.dep]], template argument
92
- deduction is performed first and then, if the context requires a
93
- candidate that is not explicit and the generated specialization is
94
  explicit [[dcl.fct.spec]], it will be removed from the candidate set.
95
  Those candidates are then handled as candidate functions in the usual
96
- way.[^2] A given name can refer to one or more function templates and
97
- also to a set of non-template functions. In such a case, the candidate
98
- functions generated from each function template are combined with the
99
- set of non-template candidate functions.
100
 
101
- A defaulted move special member function ([[class.copy.ctor]],
102
- [[class.copy.assign]]) that is defined as deleted is excluded from the
103
- set of candidate functions in all contexts. A constructor inherited from
104
- class type `C` [[class.inhctor.init]] that has a first parameter of type
105
- “reference to *cv1* `P`” (including such a constructor instantiated from
106
- a template) is excluded from the set of candidate functions when
107
- constructing an object of type *cv2* `D` if the argument list has
108
- exactly one argument and `C` is reference-related to `P` and `P` is
109
- reference-related to `D`.
 
 
 
 
 
110
 
111
  [*Example 3*:
112
 
113
  ``` cpp
114
  struct A {
@@ -131,10 +162,12 @@ B b3 = C(); // calls #4
131
 
132
  — *end example*]
133
 
134
  #### Function call syntax <a id="over.match.call">[[over.match.call]]</a>
135
 
 
 
136
  In a function call [[expr.call]]
137
 
138
  ``` bnf
139
  postfix-expression '(' expression-listₒₚₜ ')'
140
  ```
@@ -144,24 +177,27 @@ template, overload resolution is applied as specified in
144
  [[over.call.func]]. If the *postfix-expression* denotes an object of
145
  class type, overload resolution is applied as specified in
146
  [[over.call.object]].
147
 
148
  If the *postfix-expression* is the address of an overload set, overload
149
- resolution is applied using that set as described above. If the function
150
- selected by overload resolution is a non-static member function, the
151
- program is ill-formed.
152
 
153
- [*Note 1*: The resolution of the address of an overload set in other
 
 
 
 
 
 
154
  contexts is described in [[over.over]]. — *end note*]
155
 
156
  ##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
157
 
158
  Of interest in  [[over.call.func]] are only those function calls in
159
- which the *postfix-expression* ultimately contains a name that denotes
160
- one or more functions that might be called. Such a *postfix-expression*,
161
- perhaps nested arbitrarily deep in parentheses, has one of the following
162
- forms:
163
 
164
  ``` bnf
165
  postfix-expression:
166
  postfix-expression '.' id-expression
167
  postfix-expression '->' id-expression
@@ -169,52 +205,94 @@ postfix-expression:
169
  ```
170
 
171
  These represent two syntactic subcategories of function calls: qualified
172
  function calls and unqualified function calls.
173
 
174
- In qualified function calls, the name to be resolved is an
175
- *id-expression* and is preceded by an `->` or `.` operator. Since the
176
- construct `A->B` is generally equivalent to `(*A).B`, the rest of
177
- [[over]] assumes, without loss of generality, that all member function
178
- calls have been normalized to the form that uses an object and the `.`
179
- operator. Furthermore, [[over]] assumes that the *postfix-expression*
180
- that is the left operand of the `.` operator has type “cv `T`” where `T`
181
- denotes a class.[^3] Under this assumption, the *id-expression* in the
182
- call is looked up as a member function of `T` following the rules for
183
- looking up names in classes [[class.member.lookup]]. The function
184
- declarations found by that lookup constitute the set of candidate
185
- functions. The argument list is the *expression-list* in the call
186
- augmented by the addition of the left operand of the `.` operator in the
187
- normalized member function call as the implied object argument
188
- [[over.match.funcs]].
189
-
190
- In unqualified function calls, the name is not qualified by an `->` or
191
- `.` operator and has the more general form of a *primary-expression*.
192
- The name is looked up in the context of the function call following the
193
- normal rules for name lookup in expressions [[basic.lookup]]. The
194
- function declarations found by that lookup constitute the set of
195
- candidate functions. Because of the rules for name lookup, the set of
196
- candidate functions consists (1) entirely of non-member functions or (2)
197
- entirely of member functions of some class `T`. In case (1), the
198
- argument list is the same as the *expression-list* in the call. In case
199
- (2), the argument list is the *expression-list* in the call augmented by
200
- the addition of an implied object argument as in a qualified function
201
- call. If the keyword `this` [[class.this]] is in scope and refers to
202
- class `T`, or a derived class of `T`, then the implied object argument
203
- is `(*this)`. If the keyword `this` is not in scope or refers to another
204
- class, then a contrived object of type `T` becomes the implied object
205
- argument.[^4] If the argument list is augmented by a contrived object
206
- and overload resolution selects one of the non-static member functions
207
- of `T`, the call is ill-formed.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
 
209
  ##### Call to object of class type <a id="over.call.object">[[over.call.object]]</a>
210
 
211
  If the *postfix-expression* `E` in the function call syntax evaluates to
212
  a class object of type “cv `T`”, then the set of candidate functions
213
  includes at least the function call operators of `T`. The function call
214
- operators of `T` are obtained by ordinary lookup of the name
215
- `operator()` in the context of `(E).operator()`.
216
 
217
  In addition, for each non-explicit conversion function declared in `T`
218
  of the form
219
 
220
  ``` bnf
@@ -236,27 +314,23 @@ returning `R`”, a *surrogate call function* with the unique name
236
 
237
  is also considered as a candidate function. Similarly, surrogate call
238
  functions are added to the set of candidate functions for each
239
  non-explicit conversion function declared in a base class of `T`
240
  provided the function is not hidden within `T` by another intervening
241
- declaration.[^5]
242
 
243
  The argument list submitted to overload resolution consists of the
244
  argument expressions present in the function call syntax preceded by the
245
  implied object argument `(E)`.
246
 
247
- [*Note 2*: When comparing the call against the function call operators,
248
- the implied object argument is compared against the implicit object
249
- parameter of the function call operator. When comparing the call against
250
- a surrogate call function, the implied object argument is compared
251
- against the first parameter of the surrogate call function. The
252
- conversion function from which the surrogate call function was derived
253
- will be used in the conversion sequence for that parameter since it
254
- converts the implied object argument to the appropriate function pointer
255
- or reference required by that first parameter. — *end note*]
256
 
257
- [*Example 1*:
258
 
259
  ``` cpp
260
  int f1(int);
261
  int f2(float);
262
  typedef int (*fp1)(int);
@@ -302,11 +376,11 @@ void f() {
302
  ```
303
 
304
  — *end example*]
305
 
306
  If either operand has a type that is a class or an enumeration, a
307
- user-defined operator function might be declared that implements this
308
  operator or a user-defined conversion can be necessary to convert the
309
  operand to a type that is appropriate for a built-in operator. In this
310
  case, overload resolution is used to determine which operator function
311
  or built-in operator is to be invoked to implement the operator.
312
  Therefore, the operator notation is first transformed to the equivalent
@@ -332,21 +406,21 @@ binary operator `@` with a left operand of type *cv1* `T1` and a right
332
  operand of type *cv2* `T2`, four sets of candidate functions, designated
333
  *member candidates*, *non-member candidates*, *built-in candidates*, and
334
  *rewritten candidates*, are constructed as follows:
335
 
336
  - If `T1` is a complete class type or a class currently being defined,
337
- the set of member candidates is the result of the qualified lookup of
338
- `T1::operator@` [[over.call.func]]; otherwise, the set of member
339
- candidates is empty.
340
- - The set of non-member candidates is the result of the unqualified
341
- lookup of `operator@` in the context of the expression according to
342
- the usual rules for name lookup in unqualified function calls
343
- [[basic.lookup.argdep]] except that all member functions are ignored.
344
- However, if no operand has a class type, only those non-member
345
- functions in the lookup set that have a first parameter of type `T1`
346
- or “reference to cv `T1`”, when `T1` is an enumeration type, or (if
347
- there is a right operand) a second parameter of type `T2` or
348
  “reference to cv `T2`”, when `T2` is an enumeration type, are
349
  candidate functions.
350
  - For the operator `,`, the unary operator `&`, or the operator `->`,
351
  the built-in candidates set is empty. For all other operators, the
352
  built-in candidates include all of the candidate operator functions
@@ -354,32 +428,76 @@ operand of type *cv2* `T2`, four sets of candidate functions, designated
354
  - have the same operator name, and
355
  - accept the same number of operands, and
356
  - accept operand types to which the given operand or operands can be
357
  converted according to [[over.best.ics]], and
358
  - do not have the same parameter-type-list as any non-member candidate
359
- that is not a function template specialization.
 
360
  - The rewritten candidate set is determined as follows:
361
  - For the relational [[expr.rel]] operators, the rewritten candidates
362
  include all non-rewritten candidates for the expression `x <=> y`.
363
  - For the relational [[expr.rel]] and three-way comparison
364
  [[expr.spaceship]] operators, the rewritten candidates also include
365
  a synthesized candidate, with the order of the two parameters
366
  reversed, for each non-rewritten candidate for the expression
367
  `y <=> x`.
368
  - For the `!=` operator [[expr.eq]], the rewritten candidates include
369
- all non-rewritten candidates for the expression `x == y`.
 
370
  - For the equality operators, the rewritten candidates also include a
371
  synthesized candidate, with the order of the two parameters
372
  reversed, for each non-rewritten candidate for the expression
373
- `y == x`.
374
  - For all other operators, the rewritten candidate set is empty.
375
 
376
  \[*Note 2*: A candidate synthesized from a member candidate has its
377
- implicit object parameter as the second parameter, thus implicit
378
- conversions are considered for the first, but not for the second,
379
  parameter. — *end note*]
380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
  For the built-in assignment operators, conversions of the left operand
382
  are restricted as follows:
383
 
384
  - no temporaries are introduced to hold the left operand, and
385
  - no user-defined conversions are applied to the left operand to achieve
@@ -392,13 +510,13 @@ The set of candidate functions for overload resolution for some operator
392
  the built-in candidates, and the rewritten candidates for that operator
393
  `@`.
394
 
395
  The argument list contains all of the operands of the operator. The best
396
  function from the set of candidate functions is selected according to 
397
- [[over.match.viable]] and  [[over.match.best]].[^6]
398
 
399
- [*Example 2*:
400
 
401
  ``` cpp
402
  struct A {
403
  operator int();
404
  };
@@ -436,11 +554,11 @@ of the selected operation function, except that the second standard
436
  conversion sequence of a user-defined conversion sequence
437
  [[over.ics.user]] is not applied. Then the operator is treated as the
438
  corresponding built-in operator and interpreted according to
439
  [[expr.compound]].
440
 
441
- [*Example 3*:
442
 
443
  ``` cpp
444
  struct X {
445
  operator double();
446
  };
@@ -456,11 +574,11 @@ int *b = Y() + X(); // error: pointer arithmetic requires integral o
456
  — *end example*]
457
 
458
  The second operand of operator `->` is ignored in selecting an
459
  `operator->` function, and is not an argument when the `operator->`
460
  function is called. When `operator->` returns, the operator `->` is
461
- applied to the value returned, with the original second operand.[^7]
462
 
463
  If the operator is the operator `,`, the unary operator `&`, or the
464
  operator `->`, and there are no viable functions, then the operator is
465
  assumed to be the built-in operator and interpreted according to
466
  [[expr.compound]].
@@ -482,11 +600,11 @@ struct B {
482
 
483
  A a;
484
 
485
  void B::f() {
486
  operator+ (a,a); // error: global operator hidden by member
487
- a + a; // OK: calls global operator+
488
  }
489
  ```
490
 
491
  — *end note*]
492
 
@@ -520,90 +638,75 @@ Assuming that “*cv1* `T`” is the type of the object being initialized,
520
  with `T` a class type, the candidate functions are selected as follows:
521
 
522
  - The converting constructors [[class.conv.ctor]] of `T` are candidate
523
  functions.
524
  - When the type of the initializer expression is a class type “cv `S`”,
525
- the non-explicit conversion functions of `S` and its base classes are
526
- considered. When initializing a temporary object [[class.mem]] to be
527
- bound to the first parameter of a constructor where the parameter is
528
- of type “reference to *cv2* `T`” and the constructor is called with a
529
- single argument in the context of direct-initialization of an object
530
- of type “*cv3* `T`”, explicit conversion functions are also
531
- considered. Those that are not hidden within `S` and yield a type
532
- whose cv-unqualified version is the same type as `T` or is a derived
533
- class thereof are candidate functions. A call to a conversion function
534
- returning “reference to `X`” is a glvalue of type `X`, and such a
535
- conversion function is therefore considered to yield `X` for this
536
- process of selecting candidate functions.
537
 
538
  In both cases, the argument list has one argument, which is the
539
  initializer expression.
540
 
541
  [*Note 2*: This argument will be compared against the first parameter
542
- of the constructors and against the implicit object parameter of the
543
- conversion functions. — *end note*]
544
 
545
  #### Initialization by conversion function <a id="over.match.conv">[[over.match.conv]]</a>
546
 
547
  Under the conditions specified in  [[dcl.init]], as part of an
548
  initialization of an object of non-class type, a conversion function can
549
  be invoked to convert an initializer expression of class type to the
550
  type of the object being initialized. Overload resolution is used to
551
- select the conversion function to be invoked. Assuming that “*cv1* `T`”
552
- is the type of the object being initialized, and “cv `S`” is the type of
553
- the initializer expression, with `S` a class type, the candidate
554
- functions are selected as follows:
555
 
556
- - The conversion functions of `S` and its base classes are considered.
557
- Those non-explicit conversion functions that are not hidden within `S`
558
- and yield type `T` or a type that can be converted to type `T` via a
559
- standard conversion sequence [[over.ics.scs]] are candidate functions.
560
- For direct-initialization, those explicit conversion functions that
561
- are not hidden within `S` and yield type `T` or a type that can be
562
- converted to type `T` with a qualification conversion [[conv.qual]]
563
- are also candidate functions. Conversion functions that return a
564
- cv-qualified type are considered to yield the cv-unqualified version
565
- of that type for this process of selecting candidate functions. A call
566
- to a conversion function returning “reference to `X`” is a glvalue of
567
- type `X`, and such a conversion function is therefore considered to
568
- yield `X` for this process of selecting candidate functions.
569
 
570
  The argument list has one argument, which is the initializer expression.
571
 
572
- [*Note 1*: This argument will be compared against the implicit object
573
- parameter of the conversion functions. — *end note*]
574
 
575
  #### Initialization by conversion function for direct reference binding <a id="over.match.ref">[[over.match.ref]]</a>
576
 
577
  Under the conditions specified in  [[dcl.init.ref]], a reference can be
578
  bound directly to the result of applying a conversion function to an
579
  initializer expression. Overload resolution is used to select the
580
  conversion function to be invoked. Assuming that “reference to *cv1*
581
- `T`” is the type of the reference being initialized, and “cv `S`” is the
582
- type of the initializer expression, with `S` a class type, the candidate
583
  functions are selected as follows:
584
 
585
- - The conversion functions of `S` and its base classes are considered.
586
- Those non-explicit conversion functions that are not hidden within `S`
587
- and yield type “lvalue reference to *cv2* `T2`” (when initializing an
588
- lvalue reference or an rvalue reference to function) or “*cv2* `T2`”
589
- or rvalue reference to *cv2* `T2`” (when initializing an rvalue
590
- reference or an lvalue reference to function), where “*cv1* `T`” is
591
- reference-compatible [[dcl.init.ref]] with “*cv2* `T2`”, are candidate
592
- functions. For direct-initialization, those explicit conversion
593
- functions that are not hidden within `S` and yield type “lvalue
594
- reference to *cv2* `T2`” (when initializing an lvalue reference or an
595
- rvalue reference to function) or “rvalue reference to *cv2* `T2`
596
- (when initializing an rvalue reference or an lvalue reference to
597
- function), where `T2` is the same type as `T` or can be converted to
598
- type `T` with a qualification conversion [[conv.qual]], are also
599
- candidate functions.
600
 
601
  The argument list has one argument, which is the initializer expression.
602
 
603
- [*Note 1*: This argument will be compared against the implicit object
604
- parameter of the conversion functions. — *end note*]
605
 
606
  #### Initialization by list-initialization <a id="over.match.list">[[over.match.list]]</a>
607
 
608
  When objects of non-aggregate class type `T` are list-initialized such
609
  that [[dcl.init.list]] specifies that overload resolution is performed
@@ -622,15 +725,15 @@ resolution selects the constructor in two phases:
622
  consists of the elements of the initializer list.
623
 
624
  In copy-list-initialization, if an explicit constructor is chosen, the
625
  initialization is ill-formed.
626
 
627
- [*Note 1*: This differs from other situations ([[over.match.ctor]],
628
- [[over.match.copy]]), where only converting constructors are considered
629
- for copy-initialization. This restriction only applies if this
630
- initialization is part of the final result of overload
631
- resolution. — *end note*]
632
 
633
  #### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
634
 
635
  When resolving a placeholder for a deduced class type
636
  [[dcl.type.class.deduct]] where the *template-name* names a primary
@@ -669,35 +772,112 @@ the elements of the *initializer-list* or *designated-initializer-list*
669
  of the *braced-init-list*, or of the *expression-list*. For each xᵢ, let
670
  eᵢ be the corresponding aggregate element of `C` or of one of its
671
  (possibly recursive) subaggregates that would be initialized by xᵢ
672
  [[dcl.init.aggr]] if
673
 
674
- - brace elision is not considered for any aggregate element that has a
675
- dependent non-array type or an array type with a value-dependent
676
- bound, and
 
 
677
  - each non-trailing aggregate element that is a pack expansion is
678
  assumed to correspond to no elements of the initializer list, and
679
  - a trailing aggregate element that is a pack expansion is assumed to
680
  correspond to all remaining elements of the initializer list (if any).
681
 
682
  If there is no such aggregate element eᵢ for any xᵢ, the aggregate
683
  deduction candidate is not added to the set. The aggregate deduction
684
  candidate is derived as above from a hypothetical constructor
685
  `C`(`T₁`, …, `Tₙ`), where
686
 
687
- - if eᵢ is of array type and xᵢ is a *braced-init-list* or
688
- *string-literal*, `Tᵢ` is an rvalue reference to the declared type of
689
- eᵢ, and
 
690
  - otherwise, `Tᵢ` is the declared type of eᵢ,
691
 
692
  except that additional parameter packs of the form `Pⱼ` `...` are
693
  inserted into the parameter list in their original aggregate element
694
  position corresponding to each non-trailing aggregate element of type
695
  `Pⱼ` that was skipped because it was a parameter pack, and the trailing
696
  sequence of parameters corresponding to a trailing aggregate element
697
  that is a pack expansion (if any) is replaced by a single parameter of
698
- the form `Tₙ` `...`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
699
 
700
  When resolving a placeholder for a deduced class type
701
  [[dcl.type.simple]] where the *template-name* names an alias template
702
  `A`, the *defining-type-id* of `A` must be of the form
703
 
@@ -709,14 +889,16 @@ as specified in [[dcl.type.simple]]. The guides of `A` are the set of
709
  functions or function templates formed as follows. For each function or
710
  function template `f` in the guides of the template named by the
711
  *simple-template-id* of the *defining-type-id*, the template arguments
712
  of the return type of `f` are deduced from the *defining-type-id* of `A`
713
  according to the process in [[temp.deduct.type]] with the exception that
714
- deduction does not fail if not all template arguments are deduced. Let
715
- `g` denote the result of substituting these deductions into `f`. If
716
- substitution succeeds, form a function or function template `f'` with
717
- the following properties and add it to the set of guides of `A`:
 
 
718
 
719
  - The function type of `f'` is the function type of `g`.
720
  - If `f` is a function template, `f'` is a function template whose
721
  template parameter list consists of all the template parameters of `A`
722
  (including their default template arguments) that appear in the above
@@ -726,14 +908,14 @@ the following properties and add it to the set of guides of `A`:
726
  function template.
727
  - The associated constraints [[temp.constr.decl]] are the conjunction of
728
  the associated constraints of `g` and a constraint that is satisfied
729
  if and only if the arguments of `A` are deducible (see below) from the
730
  return type.
731
- - If `f` is a copy deduction candidate [[over.match.class.deduct]], then
732
- `f'` is considered to be so as well.
733
- - If `f` was generated from a *deduction-guide*
734
- [[over.match.class.deduct]], then `f'` is considered to be so as well.
735
  - The *explicit-specifier* of `f'` is the *explicit-specifier* of `g`
736
  (if any).
737
 
738
  The arguments of a template `A` are said to be deducible from a type `T`
739
  if, given a class template
@@ -771,11 +953,11 @@ If the function or function template was generated from a constructor or
771
  *deduction-guide* that had an *explicit-specifier*, each such notional
772
  constructor is considered to have that same *explicit-specifier*. All
773
  such notional constructors are considered to be public members of the
774
  hypothetical class type.
775
 
776
- [*Example 1*:
777
 
778
  ``` cpp
779
  template <class T> struct A {
780
  explicit A(const T&, ...) noexcept; // #1
781
  A(T&&, ...); // #2
@@ -853,11 +1035,11 @@ F f2 = {Types<X, Y, Z>{}, X{}, Y{}}; // OK, F<X, Y, Z> deduced
853
  F f3 = {Types<X, Y, Z>{}, X{}, W{}}; // error: conflicting types deduced; operator Y not considered
854
  ```
855
 
856
  — *end example*]
857
 
858
- [*Example 2*:
859
 
860
  ``` cpp
861
  template <class T, class U> struct C {
862
  C(T, U); // #1
863
  };
@@ -884,11 +1066,11 @@ Possible exposition-only implementation of the above procedure:
884
  template <class> class AA;
885
  template <class V> class AA<A<V>> { };
886
  template <class T> concept deduces_A = requires { sizeof(AA<T>); };
887
 
888
  // f1 is formed from the constructor #1 of C, generating the following function template
889
- template<T, U>
890
  auto f1(T, U) -> C<T, U>;
891
 
892
  // Deducing arguments for C<T, U> from C<V *, V*> deduces T as V * and U as V *;
893
  // f1' is obtained by transforming f1 as described by the above procedure.
894
  template<class V> requires deduces_A<C<V *, V *>>
 
1
  ### Candidate functions and argument lists <a id="over.match.funcs">[[over.match.funcs]]</a>
2
 
3
+ #### General <a id="over.match.funcs.general">[[over.match.funcs.general]]</a>
4
+
5
  The subclauses of  [[over.match.funcs]] describe the set of candidate
6
  functions and the argument list submitted to overload resolution in each
7
  context in which overload resolution is used. The source transformations
8
  and constructions defined in these subclauses are only for the purpose
9
  of describing the overload resolution process. An implementation is not
10
  required to use such transformations and constructions.
11
 
12
  The set of candidate functions can contain both member and non-member
13
+ functions to be resolved against the same argument list. If a member
14
+ function is
15
+
16
+ - an implicit object member function that is not a constructor, or
17
+ - a static member function and the argument list includes an implied
18
+ object argument,
19
+
20
+ it is considered to have an extra first parameter, called the
21
+ *implicit object parameter*, which represents the object for which the
22
+ member function has been called.
23
 
24
  Similarly, when appropriate, the context can construct an argument list
25
  that contains an *implied object argument* as the first argument in the
26
  list to denote the object to be operated on.
27
 
28
+ For implicit object member functions, the type of the implicit object
29
  parameter is
30
 
31
  - “lvalue reference to cv `X`” for functions declared without a
32
  *ref-qualifier* or with the `&` *ref-qualifier*
33
  - “rvalue reference to cv `X`” for functions declared with the `&&`
 
35
 
36
  where `X` is the class of which the function is a member and cv is the
37
  cv-qualification on the member function declaration.
38
 
39
  [*Example 1*: For a `const` member function of class `X`, the extra
40
+ parameter is assumed to have type “lvalue reference to
41
  `const X`”. — *end example*]
42
 
43
+ For conversion functions that are implicit object member functions, the
44
+ function is considered to be a member of the class of the implied object
45
+ argument for the purpose of defining the type of the implicit object
46
+ parameter. For non-conversion functions that are implicit object member
47
+ functions nominated by a *using-declaration* in a derived class, the
48
+ function is considered to be a member of the derived class for the
49
+ purpose of defining the type of the implicit object parameter. For
50
+ static member functions, the implicit object parameter is considered to
51
+ match any object (since if the function is selected, the object is
52
+ discarded).
53
 
54
  [*Note 1*: No actual type is established for the implicit object
55
  parameter of a static member function, and no attempt will be made to
56
  determine a conversion sequence for that parameter
57
  [[over.match.best]]. — *end note*]
58
 
59
  During overload resolution, the implied object argument is
60
  indistinguishable from other arguments. The implicit object parameter,
61
  however, retains its identity since no user-defined conversions can be
62
+ applied to achieve a type match with it. For implicit object member
63
+ functions declared without a *ref-qualifier*, even if the implicit
64
+ object parameter is not const-qualified, an rvalue can be bound to the
65
  parameter as long as in all other respects the argument can be converted
66
  to the type of the implicit object parameter.
67
 
68
  [*Note 2*: The fact that such an argument is an rvalue does not affect
69
  the ranking of implicit conversion sequences
70
  [[over.ics.rank]]. — *end note*]
71
 
72
  Because other than in list-initialization only one user-defined
73
  conversion is allowed in an implicit conversion sequence, special rules
74
+ apply when selecting the best user-defined conversion
75
+ [[over.match.best]], [[over.best.ics]].
76
 
77
  [*Example 2*:
78
 
79
  ``` cpp
80
  class T {
 
89
  T a = 1; // error: no viable conversion (T(C(1)) not considered)
90
  ```
91
 
92
  — *end example*]
93
 
94
+ In each case where conversion functions of a class `S` are considered
95
+ for initializing an object or reference of type `T`, the candidate
96
+ functions include the result of a search for the
97
+ *conversion-function-id* `operator T` in `S`.
98
+
99
+ [*Note 3*: This search can find a specialization of a conversion
100
+ function template [[basic.lookup]]. — *end note*]
101
+
102
+ Each such case also defines sets of *permissible types* for explicit and
103
+ non-explicit conversion functions; each (non-template) conversion
104
+ function that
105
+
106
+ - is a non-hidden member of `S`,
107
+ - yields a permissible type, and,
108
+ - for the former set, is non-explicit
109
+
110
+ is also a candidate function. If initializing an object, for any
111
+ permissible type cv `U`, any *cv2* `U`, *cv2* `U&`, or *cv2* `U&&` is
112
+ also a permissible type. If the set of permissible types for explicit
113
+ conversion functions is empty, any candidates that are explicit are
114
+ discarded.
115
+
116
  In each case where a candidate is a function template, candidate
117
  function template specializations are generated using template argument
118
+ deduction [[temp.over]], [[temp.deduct]]. If a constructor template or
119
+ conversion function template has an *explicit-specifier* whose
120
  *constant-expression* is value-dependent [[temp.dep]], template argument
121
+ deduction is performed first and then, if the context admits only
122
+ candidates that are not explicit and the generated specialization is
123
  explicit [[dcl.fct.spec]], it will be removed from the candidate set.
124
  Those candidates are then handled as candidate functions in the usual
125
+ way.[^1]
 
 
 
126
 
127
+ A given name can refer to, or a conversion can consider, one or more
128
+ function templates as well as a set of non-template functions. In such a
129
+ case, the candidate functions generated from each function template are
130
+ combined with the set of non-template candidate functions.
131
+
132
+ A defaulted move special member function
133
+ [[class.copy.ctor]], [[class.copy.assign]] that is defined as deleted is
134
+ excluded from the set of candidate functions in all contexts. A
135
+ constructor inherited from class type `C` [[class.inhctor.init]] that
136
+ has a first parameter of type “reference to *cv1* `P`” (including such a
137
+ constructor instantiated from a template) is excluded from the set of
138
+ candidate functions when constructing an object of type *cv2* `D` if the
139
+ argument list has exactly one argument and `C` is reference-related to
140
+ `P` and `P` is reference-related to `D`.
141
 
142
  [*Example 3*:
143
 
144
  ``` cpp
145
  struct A {
 
162
 
163
  — *end example*]
164
 
165
  #### Function call syntax <a id="over.match.call">[[over.match.call]]</a>
166
 
167
+ ##### General <a id="over.match.call.general">[[over.match.call.general]]</a>
168
+
169
  In a function call [[expr.call]]
170
 
171
  ``` bnf
172
  postfix-expression '(' expression-listₒₚₜ ')'
173
  ```
 
177
  [[over.call.func]]. If the *postfix-expression* denotes an object of
178
  class type, overload resolution is applied as specified in
179
  [[over.call.object]].
180
 
181
  If the *postfix-expression* is the address of an overload set, overload
182
+ resolution is applied using that set as described above.
 
 
183
 
184
+ [*Note 1*: No implied object argument is added in this
185
+ case. — *end note*]
186
+
187
+ If the function selected by overload resolution is an implicit object
188
+ member function, the program is ill-formed.
189
+
190
+ [*Note 2*: The resolution of the address of an overload set in other
191
  contexts is described in [[over.over]]. — *end note*]
192
 
193
  ##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
194
 
195
  Of interest in  [[over.call.func]] are only those function calls in
196
+ which the *postfix-expression* ultimately contains an *id-expression*
197
+ that denotes one or more functions. Such a *postfix-expression*, perhaps
198
+ nested arbitrarily deep in parentheses, has one of the following forms:
 
199
 
200
  ``` bnf
201
  postfix-expression:
202
  postfix-expression '.' id-expression
203
  postfix-expression '->' id-expression
 
205
  ```
206
 
207
  These represent two syntactic subcategories of function calls: qualified
208
  function calls and unqualified function calls.
209
 
210
+ In qualified function calls, the function is named by an *id-expression*
211
+ preceded by an `->` or `.` operator. Since the construct `A->B` is
212
+ generally equivalent to `(*A).B`, the rest of [[over]] assumes, without
213
+ loss of generality, that all member function calls have been normalized
214
+ to the form that uses an object and the `.` operator. Furthermore,
215
+ [[over]] assumes that the *postfix-expression* that is the left operand
216
+ of the `.` operator has type “cv `T`” where `T` denotes a class.[^2]
217
+
218
+ The function declarations found by name lookup [[class.member.lookup]]
219
+ constitute the set of candidate functions. The argument list is the
220
+ *expression-list* in the call augmented by the addition of the left
221
+ operand of the `.` operator in the normalized member function call as
222
+ the implied object argument [[over.match.funcs]].
223
+
224
+ In unqualified function calls, the function is named by a
225
+ *primary-expression*. The function declarations found by name lookup
226
+ [[basic.lookup]] constitute the set of candidate functions. Because of
227
+ the rules for name lookup, the set of candidate functions consists
228
+ either entirely of non-member functions or entirely of member functions
229
+ of some class `T`. In the former case or if the *primary-expression* is
230
+ the address of an overload set, the argument list is the same as the
231
+ *expression-list* in the call. Otherwise, the argument list is the
232
+ *expression-list* in the call augmented by the addition of an implied
233
+ object argument as in a qualified function call. If the current class
234
+ is, or is derived from, `T`, and the keyword `this` [[expr.prim.this]]
235
+ refers to it, then the implied object argument is `(*this)`. Otherwise,
236
+ a contrived object of type `T` becomes the implied object argument;[^3]
237
+
238
+ if overload resolution selects a non-static member function, the call is
239
+ ill-formed.
240
+
241
+ [*Example 1*:
242
+
243
+ ``` cpp
244
+ struct C {
245
+ void a();
246
+ void b() {
247
+ a(); // OK, (*this).a()
248
+ }
249
+
250
+ void c(this const C&); // #1
251
+ void c()&; // #2
252
+ static void c(int = 0); // #3
253
+
254
+ void d() {
255
+ c(); // error: ambiguous between #2 and #3
256
+ (C::c)(); // error: as above
257
+ (&(C::c))(); // error: cannot resolve address of overloaded this->C::c[over.over]
258
+ (&C::c)(C{}); // selects #1
259
+ (&C::c)(*this); // error: selects #2, and is ill-formed[over.match.call.general]
260
+ (&C::c)(); // selects #3
261
+ }
262
+
263
+ void f(this const C&);
264
+ void g() const {
265
+ f(); // OK, (*this).f()
266
+ f(*this); // error: no viable candidate for (*this).f(*this)
267
+ this->f(); // OK
268
+ }
269
+
270
+ static void h() {
271
+ f(); // error: contrived object argument, but overload resolution
272
+ // picked a non-static member function
273
+ f(C{}); // error: no viable candidate
274
+ C{}.f(); // OK
275
+ }
276
+
277
+ void k(this int);
278
+ operator int() const;
279
+ void m(this const C& c) {
280
+ c.k(); // OK
281
+ }
282
+ };
283
+ ```
284
+
285
+ — *end example*]
286
 
287
  ##### Call to object of class type <a id="over.call.object">[[over.call.object]]</a>
288
 
289
  If the *postfix-expression* `E` in the function call syntax evaluates to
290
  a class object of type “cv `T`”, then the set of candidate functions
291
  includes at least the function call operators of `T`. The function call
292
+ operators of `T` are the results of a search for the name `operator()`
293
+ in the scope of `T`.
294
 
295
  In addition, for each non-explicit conversion function declared in `T`
296
  of the form
297
 
298
  ``` bnf
 
314
 
315
  is also considered as a candidate function. Similarly, surrogate call
316
  functions are added to the set of candidate functions for each
317
  non-explicit conversion function declared in a base class of `T`
318
  provided the function is not hidden within `T` by another intervening
319
+ declaration.[^4]
320
 
321
  The argument list submitted to overload resolution consists of the
322
  argument expressions present in the function call syntax preceded by the
323
  implied object argument `(E)`.
324
 
325
+ [*Note 3*: When comparing the call against the function call operators,
326
+ the implied object argument is compared against the object parameter of
327
+ the function call operator. When comparing the call against a surrogate
328
+ call function, the implied object argument is compared against the first
329
+ parameter of the surrogate call function. — *end note*]
 
 
 
 
330
 
331
+ [*Example 2*:
332
 
333
  ``` cpp
334
  int f1(int);
335
  int f2(float);
336
  typedef int (*fp1)(int);
 
376
  ```
377
 
378
  — *end example*]
379
 
380
  If either operand has a type that is a class or an enumeration, a
381
+ user-defined operator function can be declared that implements this
382
  operator or a user-defined conversion can be necessary to convert the
383
  operand to a type that is appropriate for a built-in operator. In this
384
  case, overload resolution is used to determine which operator function
385
  or built-in operator is to be invoked to implement the operator.
386
  Therefore, the operator notation is first transformed to the equivalent
 
406
  operand of type *cv2* `T2`, four sets of candidate functions, designated
407
  *member candidates*, *non-member candidates*, *built-in candidates*, and
408
  *rewritten candidates*, are constructed as follows:
409
 
410
  - If `T1` is a complete class type or a class currently being defined,
411
+ the set of member candidates is the result of a search for `operator@`
412
+ in the scope of `T1`; otherwise, the set of member candidates is
413
+ empty.
414
+ - For the operators `=`, `[]`, or `->`, the set of non-member candidates
415
+ is empty; otherwise, it includes the result of unqualified lookup for
416
+ `operator@` in the rewritten function call
417
+ [[basic.lookup.unqual]], [[basic.lookup.argdep]], ignoring all member
418
+ functions. However, if no operand has a class type, only those
419
+ non-member functions in the lookup set that have a first parameter of
420
+ type `T1` or “reference to cv `T1`”, when `T1` is an enumeration type,
421
+ or (if there is a right operand) a second parameter of type `T2` or
422
  “reference to cv `T2`”, when `T2` is an enumeration type, are
423
  candidate functions.
424
  - For the operator `,`, the unary operator `&`, or the operator `->`,
425
  the built-in candidates set is empty. For all other operators, the
426
  built-in candidates include all of the candidate operator functions
 
428
  - have the same operator name, and
429
  - accept the same number of operands, and
430
  - accept operand types to which the given operand or operands can be
431
  converted according to [[over.best.ics]], and
432
  - do not have the same parameter-type-list as any non-member candidate
433
+ or rewritten non-member candidate that is not a function template
434
+ specialization.
435
  - The rewritten candidate set is determined as follows:
436
  - For the relational [[expr.rel]] operators, the rewritten candidates
437
  include all non-rewritten candidates for the expression `x <=> y`.
438
  - For the relational [[expr.rel]] and three-way comparison
439
  [[expr.spaceship]] operators, the rewritten candidates also include
440
  a synthesized candidate, with the order of the two parameters
441
  reversed, for each non-rewritten candidate for the expression
442
  `y <=> x`.
443
  - For the `!=` operator [[expr.eq]], the rewritten candidates include
444
+ all non-rewritten candidates for the expression `x == y` that are
445
+ rewrite targets with first operand `x` (see below).
446
  - For the equality operators, the rewritten candidates also include a
447
  synthesized candidate, with the order of the two parameters
448
  reversed, for each non-rewritten candidate for the expression
449
+ `y == x` that is a rewrite target with first operand `y`.
450
  - For all other operators, the rewritten candidate set is empty.
451
 
452
  \[*Note 2*: A candidate synthesized from a member candidate has its
453
+ object parameter as the second parameter, thus implicit conversions
454
+ are considered for the first, but not for the second,
455
  parameter. — *end note*]
456
 
457
+ A non-template function or function template `F` named `operator==` is a
458
+ rewrite target with first operand `o` unless a search for the name
459
+ `operator!=` in the scope S from the instantiation context of the
460
+ operator expression finds a function or function template that would
461
+ correspond [[basic.scope.scope]] to `F` if its name were `operator==`,
462
+ where S is the scope of the class type of `o` if `F` is a class member,
463
+ and the namespace scope of which `F` is a member otherwise. A function
464
+ template specialization named `operator==` is a rewrite target if its
465
+ function template is a rewrite target.
466
+
467
+ [*Example 2*:
468
+
469
+ ``` cpp
470
+ struct A {};
471
+ template<typename T> bool operator==(A, T); // #1
472
+ bool a1 = 0 == A(); // OK, calls reversed #1
473
+ template<typename T> bool operator!=(A, T);
474
+ bool a2 = 0 == A(); // error, #1 is not a rewrite target
475
+
476
+ struct B {
477
+ bool operator==(const B&); // #2
478
+ };
479
+ struct C : B {
480
+ C();
481
+ C(B);
482
+ bool operator!=(const B&); // #3
483
+ };
484
+ bool c1 = B() == C(); // OK, calls #2; reversed #2 is not a candidate
485
+ // because search for operator!= in C finds #3
486
+ bool c2 = C() == B(); // error: ambiguous between #2 found when searching C and
487
+ // reversed #2 found when searching B
488
+
489
+ struct D {};
490
+ template<typename T> bool operator==(D, T); // #4
491
+ inline namespace N {
492
+ template<typename T> bool operator!=(D, T); // #5
493
+ }
494
+ bool d1 = 0 == D(); // OK, calls reversed #4; #5 does not forbid #4 as a rewrite target
495
+ ```
496
+
497
+ — *end example*]
498
+
499
  For the built-in assignment operators, conversions of the left operand
500
  are restricted as follows:
501
 
502
  - no temporaries are introduced to hold the left operand, and
503
  - no user-defined conversions are applied to the left operand to achieve
 
510
  the built-in candidates, and the rewritten candidates for that operator
511
  `@`.
512
 
513
  The argument list contains all of the operands of the operator. The best
514
  function from the set of candidate functions is selected according to 
515
+ [[over.match.viable]] and  [[over.match.best]].[^5]
516
 
517
+ [*Example 3*:
518
 
519
  ``` cpp
520
  struct A {
521
  operator int();
522
  };
 
554
  conversion sequence of a user-defined conversion sequence
555
  [[over.ics.user]] is not applied. Then the operator is treated as the
556
  corresponding built-in operator and interpreted according to
557
  [[expr.compound]].
558
 
559
+ [*Example 4*:
560
 
561
  ``` cpp
562
  struct X {
563
  operator double();
564
  };
 
574
  — *end example*]
575
 
576
  The second operand of operator `->` is ignored in selecting an
577
  `operator->` function, and is not an argument when the `operator->`
578
  function is called. When `operator->` returns, the operator `->` is
579
+ applied to the value returned, with the original second operand.[^6]
580
 
581
  If the operator is the operator `,`, the unary operator `&`, or the
582
  operator `->`, and there are no viable functions, then the operator is
583
  assumed to be the built-in operator and interpreted according to
584
  [[expr.compound]].
 
600
 
601
  A a;
602
 
603
  void B::f() {
604
  operator+ (a,a); // error: global operator hidden by member
605
+ a + a; // OK, calls global operator+
606
  }
607
  ```
608
 
609
  — *end note*]
610
 
 
638
  with `T` a class type, the candidate functions are selected as follows:
639
 
640
  - The converting constructors [[class.conv.ctor]] of `T` are candidate
641
  functions.
642
  - When the type of the initializer expression is a class type “cv `S`”,
643
+ conversion functions are considered. The permissible types for
644
+ non-explicit conversion functions are `T` and any class derived from
645
+ `T`. When initializing a temporary object [[class.mem]] to be bound to
646
+ the first parameter of a constructor where the parameter is of type
647
+ “reference to *cv2* `T`” and the constructor is called with a single
648
+ argument in the context of direct-initialization of an object of type
649
+ “*cv3* `T`”, the permissible types for explicit conversion functions
650
+ are the same; otherwise there are none.
 
 
 
 
651
 
652
  In both cases, the argument list has one argument, which is the
653
  initializer expression.
654
 
655
  [*Note 2*: This argument will be compared against the first parameter
656
+ of the constructors and against the object parameter of the conversion
657
+ functions. — *end note*]
658
 
659
  #### Initialization by conversion function <a id="over.match.conv">[[over.match.conv]]</a>
660
 
661
  Under the conditions specified in  [[dcl.init]], as part of an
662
  initialization of an object of non-class type, a conversion function can
663
  be invoked to convert an initializer expression of class type to the
664
  type of the object being initialized. Overload resolution is used to
665
+ select the conversion function to be invoked. Assuming that “cv `T`” is
666
+ the type of the object being initialized, the candidate functions are
667
+ selected as follows:
 
668
 
669
+ - The permissible types for non-explicit conversion functions are those
670
+ that can be converted to type `T` via a standard conversion sequence
671
+ [[over.ics.scs]]. For direct-initialization, the permissible types for
672
+ explicit conversion functions are those that can be converted to type
673
+ `T` with a (possibly trivial) qualification conversion [[conv.qual]];
674
+ otherwise there are none.
 
 
 
 
 
 
 
675
 
676
  The argument list has one argument, which is the initializer expression.
677
 
678
+ [*Note 1*: This argument will be compared against the object parameter
679
+ of the conversion functions. — *end note*]
680
 
681
  #### Initialization by conversion function for direct reference binding <a id="over.match.ref">[[over.match.ref]]</a>
682
 
683
  Under the conditions specified in  [[dcl.init.ref]], a reference can be
684
  bound directly to the result of applying a conversion function to an
685
  initializer expression. Overload resolution is used to select the
686
  conversion function to be invoked. Assuming that “reference to *cv1*
687
+ `T`” is the type of the reference being initialized, the candidate
 
688
  functions are selected as follows:
689
 
690
+ - Let R be a set of types including
691
+ - “lvalue reference to *cv2* `T2`” (when initializing an lvalue
692
+ reference or an rvalue reference to function) and
693
+ - “*cv2* `T2`” and rvalue reference to *cv2* `T2`” (when initializing
694
+ an rvalue reference or an lvalue reference to function)
695
+
696
+ for any `T2`. The permissible types for non-explicit conversion
697
+ functions are the members of R where “*cv1* `T`” is
698
+ reference-compatible [[dcl.init.ref]] with “*cv2* `T2`”. For
699
+ direct-initialization, the permissible types for explicit conversion
700
+ functions are the members of R where `T2` can be converted to type `T`
701
+ with a (possibly trivial) qualification conversion [[conv.qual]];
702
+ otherwise there are none.
 
 
703
 
704
  The argument list has one argument, which is the initializer expression.
705
 
706
+ [*Note 1*: This argument will be compared against the object parameter
707
+ of the conversion functions. — *end note*]
708
 
709
  #### Initialization by list-initialization <a id="over.match.list">[[over.match.list]]</a>
710
 
711
  When objects of non-aggregate class type `T` are list-initialized such
712
  that [[dcl.init.list]] specifies that overload resolution is performed
 
725
  consists of the elements of the initializer list.
726
 
727
  In copy-list-initialization, if an explicit constructor is chosen, the
728
  initialization is ill-formed.
729
 
730
+ [*Note 1*: This differs from other situations
731
+ [[over.match.ctor]], [[over.match.copy]], where only converting
732
+ constructors are considered for copy-initialization. This restriction
733
+ only applies if this initialization is part of the final result of
734
+ overload resolution. — *end note*]
735
 
736
  #### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
737
 
738
  When resolving a placeholder for a deduced class type
739
  [[dcl.type.class.deduct]] where the *template-name* names a primary
 
772
  of the *braced-init-list*, or of the *expression-list*. For each xᵢ, let
773
  eᵢ be the corresponding aggregate element of `C` or of one of its
774
  (possibly recursive) subaggregates that would be initialized by xᵢ
775
  [[dcl.init.aggr]] if
776
 
777
+ - brace elision is not considered for any aggregate element that has
778
+ - a dependent non-array type,
779
+ - an array type with a value-dependent bound, or
780
+ - an array type with a dependent array element type and xᵢ is a string
781
+ literal; and
782
  - each non-trailing aggregate element that is a pack expansion is
783
  assumed to correspond to no elements of the initializer list, and
784
  - a trailing aggregate element that is a pack expansion is assumed to
785
  correspond to all remaining elements of the initializer list (if any).
786
 
787
  If there is no such aggregate element eᵢ for any xᵢ, the aggregate
788
  deduction candidate is not added to the set. The aggregate deduction
789
  candidate is derived as above from a hypothetical constructor
790
  `C`(`T₁`, …, `Tₙ`), where
791
 
792
+ - if eᵢ is of array type and xᵢ is a *braced-init-list*, `Tᵢ` is an
793
+ rvalue reference to the declared type of eᵢ, and
794
+ - if eᵢ is of array type and xᵢ is a *string-literal*, `Tᵢ` is an lvalue
795
+ reference to the const-qualified declared type of eᵢ, and
796
  - otherwise, `Tᵢ` is the declared type of eᵢ,
797
 
798
  except that additional parameter packs of the form `Pⱼ` `...` are
799
  inserted into the parameter list in their original aggregate element
800
  position corresponding to each non-trailing aggregate element of type
801
  `Pⱼ` that was skipped because it was a parameter pack, and the trailing
802
  sequence of parameters corresponding to a trailing aggregate element
803
  that is a pack expansion (if any) is replaced by a single parameter of
804
+ the form `Tₙ` `...`. In addition, if `C` is defined and inherits
805
+ constructors [[namespace.udecl]] from a direct base class denoted in the
806
+ *base-specifier-list* by a *class-or-decltype* `B`, let `A` be an alias
807
+ template whose template parameter list is that of `C` and whose
808
+ *defining-type-id* is `B`. If `A` is a deducible template
809
+ [[dcl.type.simple]], the set contains the guides of `A` with the return
810
+ type `R` of each guide replaced with `typename CC<R>::type` given a
811
+ class template
812
+
813
+ ``` cpp
814
+ template <typename> class CC;
815
+ ```
816
+
817
+ whose primary template is not defined and with a single partial
818
+ specialization whose template parameter list is that of `A` and whose
819
+ template argument list is a specialization of `A` with the template
820
+ argument list of `A` [[temp.dep.type]] having a member typedef `type`
821
+ designating a template specialization with the template argument list of
822
+ `A` but with `C` as the template.
823
+
824
+ [*Note 1*: Equivalently, the template parameter list of the
825
+ specialization is that of `C`, the template argument list of the
826
+ specialization is `B`, and the member typedef names `C` with the
827
+ template argument list of `C`. — *end note*]
828
+
829
+ [*Example 1*:
830
+
831
+ ``` cpp
832
+ template <typename T> struct B {
833
+ B(T);
834
+ };
835
+ template <typename T> struct C : public B<T> {
836
+ using B<T>::B;
837
+ };
838
+ template <typename T> struct D : public B<T> {};
839
+
840
+ C c(42); // OK, deduces C<int>
841
+ D d(42); // error: deduction failed, no inherited deduction guides
842
+ B(int) -> B<char>;
843
+ C c2(42); // OK, deduces C<char>
844
+
845
+ template <typename T> struct E : public B<int> {
846
+ using B<int>::B;
847
+ };
848
+
849
+ E e(42); // error: deduction failed, arguments of E cannot be deduced from introduced guides
850
+
851
+ template <typename T, typename U, typename V> struct F {
852
+ F(T, U, V);
853
+ };
854
+ template <typename T, typename U> struct G : F<U, T, int> {
855
+ using G::F::F;
856
+ }
857
+
858
+ G g(true, 'a', 1); // OK, deduces G<char, bool>
859
+
860
+ template<class T, std::size_t N>
861
+ struct H {
862
+ T array[N];
863
+ };
864
+ template<class T, std::size_t N>
865
+ struct I {
866
+ volatile T array[N];
867
+ };
868
+ template<std::size_t N>
869
+ struct J {
870
+ unsigned char array[N];
871
+ };
872
+
873
+ H h = { "abc" }; // OK, deduces H<char, 4> (not T = const char)
874
+ I i = { "def" }; // OK, deduces I<char, 4>
875
+ J j = { "ghi" }; // error: cannot bind reference to array of unsigned char to array of char in deduction
876
+ ```
877
+
878
+ — *end example*]
879
 
880
  When resolving a placeholder for a deduced class type
881
  [[dcl.type.simple]] where the *template-name* names an alias template
882
  `A`, the *defining-type-id* of `A` must be of the form
883
 
 
889
  functions or function templates formed as follows. For each function or
890
  function template `f` in the guides of the template named by the
891
  *simple-template-id* of the *defining-type-id*, the template arguments
892
  of the return type of `f` are deduced from the *defining-type-id* of `A`
893
  according to the process in [[temp.deduct.type]] with the exception that
894
+ deduction does not fail if not all template arguments are deduced. If
895
+ deduction fails for another reason, proceed with an empty set of deduced
896
+ template arguments. Let `g` denote the result of substituting these
897
+ deductions into `f`. If substitution succeeds, form a function or
898
+ function template `f'` with the following properties and add it to the
899
+ set of guides of `A`:
900
 
901
  - The function type of `f'` is the function type of `g`.
902
  - If `f` is a function template, `f'` is a function template whose
903
  template parameter list consists of all the template parameters of `A`
904
  (including their default template arguments) that appear in the above
 
908
  function template.
909
  - The associated constraints [[temp.constr.decl]] are the conjunction of
910
  the associated constraints of `g` and a constraint that is satisfied
911
  if and only if the arguments of `A` are deducible (see below) from the
912
  return type.
913
+ - If `f` is a copy deduction candidate, then `f'` is considered to be so
914
+ as well.
915
+ - If `f` was generated from a *deduction-guide* [[temp.deduct.guide]],
916
+ then `f'` is considered to be so as well.
917
  - The *explicit-specifier* of `f'` is the *explicit-specifier* of `g`
918
  (if any).
919
 
920
  The arguments of a template `A` are said to be deducible from a type `T`
921
  if, given a class template
 
953
  *deduction-guide* that had an *explicit-specifier*, each such notional
954
  constructor is considered to have that same *explicit-specifier*. All
955
  such notional constructors are considered to be public members of the
956
  hypothetical class type.
957
 
958
+ [*Example 2*:
959
 
960
  ``` cpp
961
  template <class T> struct A {
962
  explicit A(const T&, ...) noexcept; // #1
963
  A(T&&, ...); // #2
 
1035
  F f3 = {Types<X, Y, Z>{}, X{}, W{}}; // error: conflicting types deduced; operator Y not considered
1036
  ```
1037
 
1038
  — *end example*]
1039
 
1040
+ [*Example 3*:
1041
 
1042
  ``` cpp
1043
  template <class T, class U> struct C {
1044
  C(T, U); // #1
1045
  };
 
1066
  template <class> class AA;
1067
  template <class V> class AA<A<V>> { };
1068
  template <class T> concept deduces_A = requires { sizeof(AA<T>); };
1069
 
1070
  // f1 is formed from the constructor #1 of C, generating the following function template
1071
+ template<class T, class U>
1072
  auto f1(T, U) -> C<T, U>;
1073
 
1074
  // Deducing arguments for C<T, U> from C<V *, V*> deduces T as V * and U as V *;
1075
  // f1' is obtained by transforming f1 as described by the above procedure.
1076
  template<class V> requires deduces_A<C<V *, V *>>