From Jason Turner

[over.match.funcs]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpvqjasb6o/{from.md → to.md} +234 -122
tmp/tmpvqjasb6o/{from.md → to.md} RENAMED
@@ -25,55 +25,56 @@ object parameter, if present, is always the first parameter and the
25
  implied object argument, if present, is always the first argument.
26
 
27
  For non-static member functions, the type of the implicit object
28
  parameter is
29
 
30
- - “lvalue reference to *cv* `X`” for functions declared without a
31
  *ref-qualifier* or with the `&` *ref-qualifier*
32
- - “rvalue reference to *cv* `X`” for functions declared with the `&&`
33
  *ref-qualifier*
34
 
35
- where `X` is the class of which the function is a member and *cv* is the
36
- cv-qualification on the member function declaration. for a `const`
37
- member function of class `X`, the extra parameter is assumed to have
38
- type “reference to `const X`”. For conversion functions, the function is
39
- considered to be a member of the class of the implied object argument
40
- for the purpose of defining the type of the implicit object parameter.
41
- For non-conversion functions introduced by a *using-declaration* into a
42
- derived class, the function is considered to be a member of the derived
43
- class for the purpose of defining the type of the implicit object
44
- parameter. For static member functions, the implicit object parameter is
45
- considered to match any object (since if the function is selected, the
46
- object is discarded). No actual type is established for the implicit
47
- object parameter of a static member function, and no attempt will be
48
- made to determine a conversion sequence for that parameter (
49
- [[over.match.best]]).
 
 
 
 
 
50
 
51
  During overload resolution, the implied object argument is
52
  indistinguishable from other arguments. The implicit object parameter,
53
- however, retains its identity since conversions on the corresponding
54
- argument shall obey these additional rules:
 
55
 
56
- - no temporary object can be introduced to hold the argument for the
57
- implicit object parameter; and
58
- - no user-defined conversions can be applied to achieve a type match
59
- with it.
60
-
61
- For non-static member functions declared without a *ref-qualifier*, an
62
- additional rule applies:
63
-
64
- - even if the implicit object parameter is not `const`-qualified, an
65
  rvalue can be bound to the parameter as long as in all other respects
66
  the argument can be converted to the type of the implicit object
67
- parameter. The fact that such an argument is an rvalue does not affect
68
- the ranking of implicit conversion sequences ([[over.ics.rank]]).
 
69
 
70
  Because other than in list-initialization only one user-defined
71
  conversion is allowed in an implicit conversion sequence, special rules
72
  apply when selecting the best user-defined conversion (
73
  [[over.match.best]], [[over.best.ics]]).
74
 
 
 
75
  ``` cpp
76
  class T {
77
  public:
78
  T();
79
  };
@@ -83,10 +84,12 @@ public:
83
  C(int);
84
  };
85
  T a = 1; // ill-formed: T(C(1)) not tried
86
  ```
87
 
 
 
88
  In each case where a candidate is a function template, candidate
89
  function template specializations are generated using template argument
90
  deduction ([[temp.over]], [[temp.deduct]]). Those candidates are then
91
  handled as candidate functions in the usual way.[^2] A given name can
92
  refer to one or more function templates and also to a set of overloaded
@@ -114,12 +117,13 @@ class type, overload resolution is applied as specified in
114
 
115
  If the *postfix-expression* denotes the address of a set of overloaded
116
  functions and/or function templates, overload resolution is applied
117
  using that set as described above. If the function selected by overload
118
  resolution is a non-static member function, the program is ill-formed.
119
- The resolution of the address of an overload set in other contexts is
120
- described in [[over.over]].
 
121
 
122
  ##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
123
 
124
  Of interest in  [[over.call.func]] are only those function calls in
125
  which the *postfix-expression* ultimately contains a name that denotes
@@ -142,12 +146,12 @@ In qualified function calls, the name to be resolved is an
142
  construct `A->B` is generally equivalent to `(*A).B`, the rest of
143
  Clause  [[over]] assumes, without loss of generality, that all member
144
  function calls have been normalized to the form that uses an object and
145
  the `.` operator. Furthermore, Clause  [[over]] assumes that the
146
  *postfix-expression* that is the left operand of the `.` operator has
147
- type “*cv* `T`” where `T` denotes a class[^3]. Under this assumption,
148
- the *id-expression* in the call is looked up as a member function of `T`
149
  following the rules for looking up names in classes (
150
  [[class.member.lookup]]). The function declarations found by that lookup
151
  constitute the set of candidate functions. The argument list is the
152
  *expression-list* in the call augmented by the addition of the left
153
  operand of the `.` operator in the normalized member function call as
@@ -173,32 +177,33 @@ and overload resolution selects one of the non-static member functions
173
  of `T`, the call is ill-formed.
174
 
175
  ##### Call to object of class type <a id="over.call.object">[[over.call.object]]</a>
176
 
177
  If the *primary-expression* `E` in the function call syntax evaluates to
178
- a class object of type “*cv* `T`”, then the set of candidate functions
179
  includes at least the function call operators of `T`. The function call
180
  operators of `T` are obtained by ordinary lookup of the name
181
  `operator()` in the context of `(E).operator()`.
182
 
183
  In addition, for each non-explicit conversion function declared in `T`
184
  of the form
185
 
186
  ``` bnf
187
- 'operator' conversion-type-id '( )' cv-qualifier ref-qualifierₒₚₜ exception-specificationₒₚₜ attribute-specifier-seqₒₚₜ ';'
188
  ```
189
 
190
  where *cv-qualifier* is the same cv-qualification as, or a greater
191
- cv-qualification than, *cv*, and where *conversion-type-id* denotes the
192
- type “pointer to function of (`P1`,...,`Pn)` returning `R`”, or the type
193
- “reference to pointer to function of (`P1`,...,`Pn)` returning `R`”, or
194
- the type “reference to function of (`P1`,...,`Pn)` returning `R`”, a
195
  *surrogate call function* with the unique name *call-function* and
196
  having the form
197
 
198
  ``` bnf
199
- 'R' call-function '(' conversion-type-id 'F, P1 a1, ... ,Pn an)' '{ return F (a1,... ,an); }'
 
200
  ```
201
 
202
  is also considered as a candidate function. Similarly, surrogate call
203
  functions are added to the set of candidate functions for each
204
  non-explicit conversion function declared in a base class of `T`
@@ -212,82 +217,92 @@ then be invoked with the arguments of the call. If the conversion
212
  function cannot be called (e.g., because of an ambiguity), the program
213
  is ill-formed.
214
 
215
  The argument list submitted to overload resolution consists of the
216
  argument expressions present in the function call syntax preceded by the
217
- implied object argument `(E)`. When comparing the call against the
218
- function call operators, the implied object argument is compared against
219
- the implicit object parameter of the function call operator. When
220
- comparing the call against a surrogate call function, the implied object
221
- argument is compared against the first parameter of the surrogate call
222
- function. The conversion function from which the surrogate call function
223
- was derived will be used in the conversion sequence for that parameter
224
- since it converts the implied object argument to the appropriate
225
- function pointer or reference required by that first parameter.
 
 
 
 
226
 
227
  ``` cpp
228
  int f1(int);
229
  int f2(float);
230
  typedef int (*fp1)(int);
231
  typedef int (*fp2)(float);
232
  struct A {
233
  operator fp1() { return f1; }
234
  operator fp2() { return f2; }
235
  } a;
236
- int i = a(1); // calls f1 via pointer returned from
237
- // conversion function
238
  ```
239
 
 
 
240
  #### Operators in expressions <a id="over.match.oper">[[over.match.oper]]</a>
241
 
242
  If no operand of an operator in an expression has a type that is a class
243
  or an enumeration, the operator is assumed to be a built-in operator and
244
- interpreted according to Clause  [[expr]]. Because `.`, `.*`, and `::`
245
- cannot be overloaded, these operators are always built-in operators
246
- interpreted according to Clause  [[expr]]. `?:` cannot be overloaded,
247
- but the rules in this subclause are used to determine the conversions to
248
- be applied to the second and third operands when they have class or
249
- enumeration type ([[expr.cond]]).
 
 
 
 
250
 
251
  ``` cpp
252
  struct String {
253
  String (const String&);
254
  String (const char*);
255
  operator const char* ();
256
  };
257
  String operator + (const String&, const String&);
258
 
259
- void f(void) {
260
- const char* p= "one" + "two"; // ill-formed because neither
261
- // operand has class or enumeration type
262
- int I = 1 + 1; // Always evaluates to 2 even if
263
- // class or enumeration types exist that
264
- // would perform the operation.
265
  }
266
  ```
267
 
 
 
268
  If either operand has a type that is a class or an enumeration, a
269
  user-defined operator function might be declared that implements this
270
  operator or a user-defined conversion can be necessary to convert the
271
  operand to a type that is appropriate for a built-in operator. In this
272
  case, overload resolution is used to determine which operator function
273
  or built-in operator is to be invoked to implement the operator.
274
  Therefore, the operator notation is first transformed to the equivalent
275
  function-call notation as summarized in Table  [[tab:over.rel.op.func]]
276
  (where `@` denotes one of the operators covered in the specified
277
- subclause).
 
278
 
279
  **Table: Relationship between operator and function call notation** <a id="tab:over.rel.op.func">[tab:over.rel.op.func]</a>
280
 
281
  | Subclause | Expression | As member function | As non-member function |
282
- | ------------ | ---------- | ------------------ | ---------------------- |
283
- | (a) |
284
- | (a, b) |
285
- | [[over.ass]] | a=b | (a).operator= (b) | |
286
- | [[over.sub]] | a[b] | (a).operator[](b) | |
287
- | [[over.ref]] | a-> | (a).operator-> ( ) | |
288
- | (a, 0) |
289
 
290
 
291
  For a unary operator `@` with an operand of a type whose cv-unqualified
292
  version is `T1`, and for a binary operator `@` with a left operand of a
293
  type whose cv-unqualified version is `T1` and a right operand of a type
@@ -303,14 +318,14 @@ candidates*, are constructed as follows:
303
  lookup of `operator@` in the context of the expression according to
304
  the usual rules for name lookup in unqualified function calls (
305
  [[basic.lookup.argdep]]) except that all member functions are ignored.
306
  However, if no operand has a class type, only those non-member
307
  functions in the lookup set that have a first parameter of type `T1`
308
- or “reference to (possibly cv-qualified) `T1`”, when `T1` is an
309
- enumeration type, or (if there is a right operand) a second parameter
310
- of type `T2` or “reference to (possibly cv-qualified) `T2`”, when `T2`
311
- is an enumeration type, are candidate functions.
312
  - For the operator `,`, the unary operator `&`, or the operator `->`,
313
  the built-in candidates set is empty. For all other operators, the
314
  built-in candidates include all of the candidate operator functions
315
  defined in  [[over.built]] that, compared to the given operator,
316
  - have the same operator name, and
@@ -334,10 +349,12 @@ the member candidates, the non-member candidates, and the built-in
334
  candidates. The argument list contains all of the operands of the
335
  operator. The best function from the set of candidate functions is
336
  selected according to  [[over.match.viable]] and 
337
  [[over.match.best]].[^6]
338
 
 
 
339
  ``` cpp
340
  struct A {
341
  operator int();
342
  };
343
  A operator+(const A&, const A&);
@@ -345,18 +362,22 @@ void m() {
345
  A a, b;
346
  a + b; // operator+(a, b) chosen over int(a) + int(b)
347
  }
348
  ```
349
 
 
 
350
  If a built-in candidate is selected by overload resolution, the operands
351
  of class type are converted to the types of the corresponding parameters
352
  of the selected operation function, except that the second standard
353
  conversion sequence of a user-defined conversion sequence (
354
  [[over.ics.user]]) is not applied. Then the operator is treated as the
355
  corresponding built-in operator and interpreted according to Clause 
356
  [[expr]].
357
 
 
 
358
  ``` cpp
359
  struct X {
360
  operator double();
361
  };
362
 
@@ -366,20 +387,24 @@ struct Y {
366
 
367
  int *a = Y() + 100.0; // error: pointer arithmetic requires integral operand
368
  int *b = Y() + X(); // error: pointer arithmetic requires integral operand
369
  ```
370
 
 
 
371
  The second operand of operator `->` is ignored in selecting an
372
  `operator->` function, and is not an argument when the `operator->`
373
  function is called. When `operator->` returns, the operator `->` is
374
  applied to the value returned, with the original second operand.[^7]
375
 
376
  If the operator is the operator `,`, the unary operator `&`, or the
377
  operator `->`, and there are no viable functions, then the operator is
378
  assumed to be the built-in operator and interpreted according to Clause 
379
  [[expr]].
380
 
 
 
381
  The lookup rules for operators in expressions are different than the
382
  lookup rules for operator function names in a function call, as shown in
383
  the following example:
384
 
385
  ``` cpp
@@ -397,64 +422,72 @@ void B::f() {
397
  operator+ (a,a); // error: global operator hidden by member
398
  a + a; // OK: calls global operator+
399
  }
400
  ```
401
 
 
 
402
  #### Initialization by constructor <a id="over.match.ctor">[[over.match.ctor]]</a>
403
 
404
- When objects of class type are direct-initialized ([[dcl.init]]), or
405
  copy-initialized from an expression of the same or a derived class
406
- type ([[dcl.init]]), overload resolution selects the constructor. For
407
- direct-initialization, the candidate functions are all the constructors
408
- of the class of the object being initialized. For copy-initialization,
409
- the candidate functions are all the converting constructors (
 
 
410
  [[class.conv.ctor]]) of that class. The argument list is the
411
  *expression-list* or *assignment-expression* of the *initializer*.
412
 
413
  #### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
414
 
415
  Under the conditions specified in  [[dcl.init]], as part of a
416
  copy-initialization of an object of class type, a user-defined
417
  conversion can be invoked to convert an initializer expression to the
418
  type of the object being initialized. Overload resolution is used to
419
- select the user-defined conversion to be invoked. The conversion
420
- performed for indirect binding to a reference to a possibly cv-qualified
421
- class type is determined in terms of a corresponding non-reference
422
- copy-initialization. Assuming that “*cv1* `T`” is the type of the object
423
- being initialized, with `T` a class type, the candidate functions are
424
- selected as follows:
 
 
425
 
426
  - The converting constructors ([[class.conv.ctor]]) of `T` are
427
  candidate functions.
428
- - When the type of the initializer expression is a class type “*cv*
429
- `S`”, the non-explicit conversion functions of `S` and its base
430
- classes are considered. When initializing a temporary to be bound to
431
- the first parameter of a constructor that takes a reference to
432
- possibly cv-qualified `T` as its first argument, called with a single
433
- argument in the context of direct-initialization of an object of type
434
- “*cv2* `T`”, explicit conversion functions are also considered. Those
435
- that are not hidden within `S` and yield a type whose cv-unqualified
436
- version is the same type as `T` or is a derived class thereof are
437
- candidate functions. Conversion functions that return “reference to
438
- `X`” return lvalues or xvalues, depending on the type of reference, of
439
- type `X` and are therefore considered to yield `X` for this process of
440
- selecting candidate functions.
441
 
442
  In both cases, the argument list has one argument, which is the
443
- initializer expression. This argument will be compared against the first
444
- parameter of the constructors and against the implicit object parameter
445
- of the conversion functions.
 
 
446
 
447
  #### Initialization by conversion function <a id="over.match.conv">[[over.match.conv]]</a>
448
 
449
  Under the conditions specified in  [[dcl.init]], as part of an
450
- initialization of an object of nonclass type, a conversion function can
451
  be invoked to convert an initializer expression of class type to the
452
  type of the object being initialized. Overload resolution is used to
453
  select the conversion function to be invoked. Assuming that “*cv1* `T`”
454
- is the type of the object being initialized, and “*cv* `S`” is the type
455
- of the initializer expression, with `S` a class type, the candidate
456
  functions are selected as follows:
457
 
458
  - The conversion functions of `S` and its base classes are considered.
459
  Those non-explicit conversion functions that are not hidden within `S`
460
  and yield type `T` or a type that can be converted to type `T` via a
@@ -469,46 +502,50 @@ functions are selected as follows:
469
  return lvalues or xvalues, depending on the type of reference, of type
470
  “*cv2* `X`” and are therefore considered to yield `X` for this process
471
  of selecting candidate functions.
472
 
473
  The argument list has one argument, which is the initializer expression.
474
- This argument will be compared against the implicit object parameter of
475
- the conversion functions.
 
476
 
477
  #### Initialization by conversion function for direct reference binding <a id="over.match.ref">[[over.match.ref]]</a>
478
 
479
  Under the conditions specified in  [[dcl.init.ref]], a reference can be
480
  bound directly to a glvalue or class prvalue that is the result of
481
  applying a conversion function to an initializer expression. Overload
482
  resolution is used to select the conversion function to be invoked.
483
- Assuming that “*cv1* `T`” is the underlying type of the reference being
484
- initialized, and “*cv* `S`” is the type of the initializer expression,
485
- with `S` a class type, the candidate functions are selected as follows:
 
486
 
487
  - The conversion functions of `S` and its base classes are considered.
488
  Those non-explicit conversion functions that are not hidden within `S`
489
  and yield type “lvalue reference to *cv2* `T2`” (when initializing an
490
- lvalue reference or an rvalue reference to function) or “ `T2`” or
491
- “rvalue reference to `T2`” (when initializing an rvalue reference or
492
- an lvalue reference to function), where “*cv1* `T`” is
493
  reference-compatible ([[dcl.init.ref]]) with “*cv2* `T2`”, are
494
  candidate functions. For direct-initialization, those explicit
495
  conversion functions that are not hidden within `S` and yield type
496
  “lvalue reference to *cv2* `T2`” or “*cv2* `T2`” or “rvalue reference
497
- to *cv2* `T2`,” respectively, where `T2` is the same type as `T` or
498
  can be converted to type `T` with a qualification conversion (
499
  [[conv.qual]]), are also candidate functions.
500
 
501
  The argument list has one argument, which is the initializer expression.
502
- This argument will be compared against the implicit object parameter of
503
- the conversion functions.
 
504
 
505
  #### Initialization by list-initialization <a id="over.match.list">[[over.match.list]]</a>
506
 
507
- When objects of non-aggregate class type `T` are list-initialized (
508
- [[dcl.init.list]]), overload resolution selects the constructor in two
509
- phases:
 
510
 
511
  - Initially, the candidate functions are the initializer-list
512
  constructors ([[dcl.init.list]]) of the class `T` and the argument
513
  list consists of the initializer list as a single argument.
514
  - If no viable initializer-list constructor is found, overload
@@ -517,10 +554,85 @@ phases:
517
  the elements of the initializer list.
518
 
519
  If the initializer list has no elements and `T` has a default
520
  constructor, the first phase is omitted. In copy-list-initialization, if
521
  an `explicit` constructor is chosen, the initialization is ill-formed.
522
- This differs from other situations ([[over.match.ctor]], 
 
523
  [[over.match.copy]]), where only converting constructors are considered
524
  for copy-initialization. This restriction only applies if this
525
- initialization is part of the final result of overload resolution.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
 
 
25
  implied object argument, if present, is always the first argument.
26
 
27
  For non-static member functions, the type of the implicit object
28
  parameter is
29
 
30
+ - “lvalue reference to cv `X`” for functions declared without a
31
  *ref-qualifier* or with the `&` *ref-qualifier*
32
+ - “rvalue reference to cv `X`” for functions declared with the `&&`
33
  *ref-qualifier*
34
 
35
+ where `X` is the class of which the function is a member and cv is the
36
+ cv-qualification on the member function declaration.
37
+
38
+ [*Example 1*: For a `const` member function of class `X`, the extra
39
+ parameter is assumed to have type “reference to
40
+ `const X`”. *end example*]
41
+
42
+ For conversion functions, the function is considered to be a member of
43
+ the class of the implied object argument for the purpose of defining the
44
+ type of the implicit object parameter. For non-conversion functions
45
+ introduced by a *using-declaration* into a derived class, the function
46
+ is considered to be a member of the derived class for the purpose of
47
+ defining the type of the implicit object parameter. For static member
48
+ functions, the implicit object parameter is considered to match any
49
+ object (since if the function is selected, the object is discarded).
50
+
51
+ [*Note 1*: No actual type is established for the implicit object
52
+ parameter of a static member function, and no attempt will be made to
53
+ determine a conversion sequence for that parameter (
54
+ [[over.match.best]]). — *end note*]
55
 
56
  During overload resolution, the implied object argument is
57
  indistinguishable from other arguments. The implicit object parameter,
58
+ however, retains its identity since no user-defined conversions can be
59
+ applied to achieve a type match with it. For non-static member functions
60
+ declared without a *ref-qualifier*, an additional rule applies:
61
 
62
+ - even if the implicit object parameter is not const-qualified, an
 
 
 
 
 
 
 
 
63
  rvalue can be bound to the parameter as long as in all other respects
64
  the argument can be converted to the type of the implicit object
65
+ parameter. \[*Note 2*: The fact that such an argument is an rvalue
66
+ does not affect the ranking of implicit conversion sequences (
67
+ [[over.ics.rank]]). — *end note*]
68
 
69
  Because other than in list-initialization only one user-defined
70
  conversion is allowed in an implicit conversion sequence, special rules
71
  apply when selecting the best user-defined conversion (
72
  [[over.match.best]], [[over.best.ics]]).
73
 
74
+ [*Example 2*:
75
+
76
  ``` cpp
77
  class T {
78
  public:
79
  T();
80
  };
 
84
  C(int);
85
  };
86
  T a = 1; // ill-formed: T(C(1)) not tried
87
  ```
88
 
89
+ — *end example*]
90
+
91
  In each case where a candidate is a function template, candidate
92
  function template specializations are generated using template argument
93
  deduction ([[temp.over]], [[temp.deduct]]). Those candidates are then
94
  handled as candidate functions in the usual way.[^2] A given name can
95
  refer to one or more function templates and also to a set of overloaded
 
117
 
118
  If the *postfix-expression* denotes the address of a set of overloaded
119
  functions and/or function templates, overload resolution is applied
120
  using that set as described above. If the function selected by overload
121
  resolution is a non-static member function, the program is ill-formed.
122
+
123
+ [*Note 1*: The resolution of the address of an overload set in other
124
+ contexts is described in [[over.over]]. — *end note*]
125
 
126
  ##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
127
 
128
  Of interest in  [[over.call.func]] are only those function calls in
129
  which the *postfix-expression* ultimately contains a name that denotes
 
146
  construct `A->B` is generally equivalent to `(*A).B`, the rest of
147
  Clause  [[over]] assumes, without loss of generality, that all member
148
  function calls have been normalized to the form that uses an object and
149
  the `.` operator. Furthermore, Clause  [[over]] assumes that the
150
  *postfix-expression* that is the left operand of the `.` operator has
151
+ type “cv `T`” where `T` denotes a class[^3]. Under this assumption, the
152
+ *id-expression* in the call is looked up as a member function of `T`
153
  following the rules for looking up names in classes (
154
  [[class.member.lookup]]). The function declarations found by that lookup
155
  constitute the set of candidate functions. The argument list is the
156
  *expression-list* in the call augmented by the addition of the left
157
  operand of the `.` operator in the normalized member function call as
 
177
  of `T`, the call is ill-formed.
178
 
179
  ##### Call to object of class type <a id="over.call.object">[[over.call.object]]</a>
180
 
181
  If the *primary-expression* `E` in the function call syntax evaluates to
182
+ a class object of type “cv `T`”, then the set of candidate functions
183
  includes at least the function call operators of `T`. The function call
184
  operators of `T` are obtained by ordinary lookup of the name
185
  `operator()` in the context of `(E).operator()`.
186
 
187
  In addition, for each non-explicit conversion function declared in `T`
188
  of the form
189
 
190
  ``` bnf
191
+ 'operator' conversion-type-id '( )' cv-qualifier ref-qualifierₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ ';'
192
  ```
193
 
194
  where *cv-qualifier* is the same cv-qualification as, or a greater
195
+ cv-qualification than, cv, and where *conversion-type-id* denotes the
196
+ type “pointer to function of (`P₁`,, `Pₙ`) returning `R`”, or the type
197
+ “reference to pointer to function of (`P₁`,, `Pₙ`) returning `R`”, or
198
+ the type “reference to function of (`P₁`,, `Pₙ`) returning `R`”, a
199
  *surrogate call function* with the unique name *call-function* and
200
  having the form
201
 
202
  ``` bnf
203
+ 'R' call-function '(' conversion-type-id \ %
204
+ 'F, P₁ a₁, …, Pₙ aₙ)' '{ return F (a₁, …, aₙ); }'
205
  ```
206
 
207
  is also considered as a candidate function. Similarly, surrogate call
208
  functions are added to the set of candidate functions for each
209
  non-explicit conversion function declared in a base class of `T`
 
217
  function cannot be called (e.g., because of an ambiguity), the program
218
  is ill-formed.
219
 
220
  The argument list submitted to overload resolution consists of the
221
  argument expressions present in the function call syntax preceded by the
222
+ implied object argument `(E)`.
223
+
224
+ [*Note 2*: When comparing the call against the function call operators,
225
+ the implied object argument is compared against the implicit object
226
+ parameter of the function call operator. When comparing the call against
227
+ a surrogate call function, the implied object argument is compared
228
+ against the first parameter of the surrogate call function. The
229
+ conversion function from which the surrogate call function was derived
230
+ will be used in the conversion sequence for that parameter since it
231
+ converts the implied object argument to the appropriate function pointer
232
+ or reference required by that first parameter. — *end note*]
233
+
234
+ [*Example 1*:
235
 
236
  ``` cpp
237
  int f1(int);
238
  int f2(float);
239
  typedef int (*fp1)(int);
240
  typedef int (*fp2)(float);
241
  struct A {
242
  operator fp1() { return f1; }
243
  operator fp2() { return f2; }
244
  } a;
245
+ int i = a(1); // calls f1 via pointer returned from conversion function
 
246
  ```
247
 
248
+ — *end example*]
249
+
250
  #### Operators in expressions <a id="over.match.oper">[[over.match.oper]]</a>
251
 
252
  If no operand of an operator in an expression has a type that is a class
253
  or an enumeration, the operator is assumed to be a built-in operator and
254
+ interpreted according to Clause  [[expr]].
255
+
256
+ [*Note 1*: Because `.`, `.*`, and `::` cannot be overloaded, these
257
+ operators are always built-in operators interpreted according to Clause 
258
+ [[expr]]. `?:` cannot be overloaded, but the rules in this subclause are
259
+ used to determine the conversions to be applied to the second and third
260
+ operands when they have class or enumeration type (
261
+ [[expr.cond]]). — *end note*]
262
+
263
+ [*Example 1*:
264
 
265
  ``` cpp
266
  struct String {
267
  String (const String&);
268
  String (const char*);
269
  operator const char* ();
270
  };
271
  String operator + (const String&, const String&);
272
 
273
+ void f() {
274
+ const char* p= "one" + "two"; // ill-formed because neither operand has class or enumeration type
275
+ int I = 1 + 1; // always evaluates to 2 even if class or enumeration types exist
276
+ // that would perform the operation.
 
 
277
  }
278
  ```
279
 
280
+ — *end example*]
281
+
282
  If either operand has a type that is a class or an enumeration, a
283
  user-defined operator function might be declared that implements this
284
  operator or a user-defined conversion can be necessary to convert the
285
  operand to a type that is appropriate for a built-in operator. In this
286
  case, overload resolution is used to determine which operator function
287
  or built-in operator is to be invoked to implement the operator.
288
  Therefore, the operator notation is first transformed to the equivalent
289
  function-call notation as summarized in Table  [[tab:over.rel.op.func]]
290
  (where `@` denotes one of the operators covered in the specified
291
+ subclause). However, the operands are sequenced in the order prescribed
292
+ for the built-in operator (Clause  [[expr]]).
293
 
294
  **Table: Relationship between operator and function call notation** <a id="tab:over.rel.op.func">[tab:over.rel.op.func]</a>
295
 
296
  | Subclause | Expression | As member function | As non-member function |
297
+ | ------------ | ---------- | ------------------- | ---------------------- |
298
+ | (a)} |
299
+ | (a, b)} |
300
+ | [[over.ass]] | `a=b` | `(a).operator= (b)` | |
301
+ | [[over.sub]] | `a[b]` | `(a).operator[](b)` | |
302
+ | [[over.ref]] | `a->` | `(a).operator->( )` | |
303
+ | (a, 0)} |
304
 
305
 
306
  For a unary operator `@` with an operand of a type whose cv-unqualified
307
  version is `T1`, and for a binary operator `@` with a left operand of a
308
  type whose cv-unqualified version is `T1` and a right operand of a type
 
318
  lookup of `operator@` in the context of the expression according to
319
  the usual rules for name lookup in unqualified function calls (
320
  [[basic.lookup.argdep]]) except that all member functions are ignored.
321
  However, if no operand has a class type, only those non-member
322
  functions in the lookup set that have a first parameter of type `T1`
323
+ or “reference to cv `T1`”, when `T1` is an enumeration type, or (if
324
+ there is a right operand) a second parameter of type `T2` or
325
+ “reference to cv `T2`”, when `T2` is an enumeration type, are
326
+ candidate functions.
327
  - For the operator `,`, the unary operator `&`, or the operator `->`,
328
  the built-in candidates set is empty. For all other operators, the
329
  built-in candidates include all of the candidate operator functions
330
  defined in  [[over.built]] that, compared to the given operator,
331
  - have the same operator name, and
 
349
  candidates. The argument list contains all of the operands of the
350
  operator. The best function from the set of candidate functions is
351
  selected according to  [[over.match.viable]] and 
352
  [[over.match.best]].[^6]
353
 
354
+ [*Example 2*:
355
+
356
  ``` cpp
357
  struct A {
358
  operator int();
359
  };
360
  A operator+(const A&, const A&);
 
362
  A a, b;
363
  a + b; // operator+(a, b) chosen over int(a) + int(b)
364
  }
365
  ```
366
 
367
+ — *end example*]
368
+
369
  If a built-in candidate is selected by overload resolution, the operands
370
  of class type are converted to the types of the corresponding parameters
371
  of the selected operation function, except that the second standard
372
  conversion sequence of a user-defined conversion sequence (
373
  [[over.ics.user]]) is not applied. Then the operator is treated as the
374
  corresponding built-in operator and interpreted according to Clause 
375
  [[expr]].
376
 
377
+ [*Example 3*:
378
+
379
  ``` cpp
380
  struct X {
381
  operator double();
382
  };
383
 
 
387
 
388
  int *a = Y() + 100.0; // error: pointer arithmetic requires integral operand
389
  int *b = Y() + X(); // error: pointer arithmetic requires integral operand
390
  ```
391
 
392
+ — *end example*]
393
+
394
  The second operand of operator `->` is ignored in selecting an
395
  `operator->` function, and is not an argument when the `operator->`
396
  function is called. When `operator->` returns, the operator `->` is
397
  applied to the value returned, with the original second operand.[^7]
398
 
399
  If the operator is the operator `,`, the unary operator `&`, or the
400
  operator `->`, and there are no viable functions, then the operator is
401
  assumed to be the built-in operator and interpreted according to Clause 
402
  [[expr]].
403
 
404
+ [*Note 2*:
405
+
406
  The lookup rules for operators in expressions are different than the
407
  lookup rules for operator function names in a function call, as shown in
408
  the following example:
409
 
410
  ``` cpp
 
422
  operator+ (a,a); // error: global operator hidden by member
423
  a + a; // OK: calls global operator+
424
  }
425
  ```
426
 
427
+ — *end note*]
428
+
429
  #### Initialization by constructor <a id="over.match.ctor">[[over.match.ctor]]</a>
430
 
431
+ When objects of class type are direct-initialized ([[dcl.init]]),
432
  copy-initialized from an expression of the same or a derived class
433
+ type ([[dcl.init]]), or default-initialized ([[dcl.init]]), overload
434
+ resolution selects the constructor. For direct-initialization or
435
+ default-initialization that is not in the context of
436
+ copy-initialization, the candidate functions are all the constructors of
437
+ the class of the object being initialized. For copy-initialization, the
438
+ candidate functions are all the converting constructors (
439
  [[class.conv.ctor]]) of that class. The argument list is the
440
  *expression-list* or *assignment-expression* of the *initializer*.
441
 
442
  #### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
443
 
444
  Under the conditions specified in  [[dcl.init]], as part of a
445
  copy-initialization of an object of class type, a user-defined
446
  conversion can be invoked to convert an initializer expression to the
447
  type of the object being initialized. Overload resolution is used to
448
+ select the user-defined conversion to be invoked.
449
+
450
+ [*Note 1*: The conversion performed for indirect binding to a reference
451
+ to a possibly cv-qualified class type is determined in terms of a
452
+ corresponding non-reference copy-initialization. *end note*]
453
+
454
+ Assuming that “*cv1* `T`” is the type of the object being initialized,
455
+ with `T` a class type, the candidate functions are selected as follows:
456
 
457
  - The converting constructors ([[class.conv.ctor]]) of `T` are
458
  candidate functions.
459
+ - When the type of the initializer expression is a class type “cv `S`”,
460
+ the non-explicit conversion functions of `S` and its base classes are
461
+ considered. When initializing a temporary to be bound to the first
462
+ parameter of a constructor where the parameter is of type “reference
463
+ to possibly cv-qualified `T` and the constructor is called with a
464
+ single argument in the context of direct-initialization of an object
465
+ of type “*cv2* `T`”, explicit conversion functions are also
466
+ considered. Those that are not hidden within `S` and yield a type
467
+ whose cv-unqualified version is the same type as `T` or is a derived
468
+ class thereof are candidate functions. Conversion functions that
469
+ return “reference to `X`” return lvalues or xvalues, depending on the
470
+ type of reference, of type `X` and are therefore considered to yield
471
+ `X` for this process of selecting candidate functions.
472
 
473
  In both cases, the argument list has one argument, which is the
474
+ initializer expression.
475
+
476
+ [*Note 2*: This argument will be compared against the first parameter
477
+ of the constructors and against the implicit object parameter of the
478
+ conversion functions. — *end note*]
479
 
480
  #### Initialization by conversion function <a id="over.match.conv">[[over.match.conv]]</a>
481
 
482
  Under the conditions specified in  [[dcl.init]], as part of an
483
+ initialization of an object of non-class type, a conversion function can
484
  be invoked to convert an initializer expression of class type to the
485
  type of the object being initialized. Overload resolution is used to
486
  select the conversion function to be invoked. Assuming that “*cv1* `T`”
487
+ is the type of the object being initialized, and “cv `S`” is the type of
488
+ the initializer expression, with `S` a class type, the candidate
489
  functions are selected as follows:
490
 
491
  - The conversion functions of `S` and its base classes are considered.
492
  Those non-explicit conversion functions that are not hidden within `S`
493
  and yield type `T` or a type that can be converted to type `T` via a
 
502
  return lvalues or xvalues, depending on the type of reference, of type
503
  “*cv2* `X`” and are therefore considered to yield `X` for this process
504
  of selecting candidate functions.
505
 
506
  The argument list has one argument, which is the initializer expression.
507
+
508
+ [*Note 1*: This argument will be compared against the implicit object
509
+ parameter of the conversion functions. — *end note*]
510
 
511
  #### Initialization by conversion function for direct reference binding <a id="over.match.ref">[[over.match.ref]]</a>
512
 
513
  Under the conditions specified in  [[dcl.init.ref]], a reference can be
514
  bound directly to a glvalue or class prvalue that is the result of
515
  applying a conversion function to an initializer expression. Overload
516
  resolution is used to select the conversion function to be invoked.
517
+ Assuming that “reference to *cv1* `T`” is the type of the reference
518
+ being initialized, and “cv `S`” is the type of the initializer
519
+ expression, with `S` a class type, the candidate functions are selected
520
+ as follows:
521
 
522
  - The conversion functions of `S` and its base classes are considered.
523
  Those non-explicit conversion functions that are not hidden within `S`
524
  and yield type “lvalue reference to *cv2* `T2`” (when initializing an
525
+ lvalue reference or an rvalue reference to function) or “*cv2* `T2`”
526
+ or “rvalue reference to *cv2* `T2`” (when initializing an rvalue
527
+ reference or an lvalue reference to function), where “*cv1* `T`” is
528
  reference-compatible ([[dcl.init.ref]]) with “*cv2* `T2`”, are
529
  candidate functions. For direct-initialization, those explicit
530
  conversion functions that are not hidden within `S` and yield type
531
  “lvalue reference to *cv2* `T2`” or “*cv2* `T2`” or “rvalue reference
532
+ to *cv2* `T2`”, respectively, where `T2` is the same type as `T` or
533
  can be converted to type `T` with a qualification conversion (
534
  [[conv.qual]]), are also candidate functions.
535
 
536
  The argument list has one argument, which is the initializer expression.
537
+
538
+ [*Note 1*: This argument will be compared against the implicit object
539
+ parameter of the conversion functions. — *end note*]
540
 
541
  #### Initialization by list-initialization <a id="over.match.list">[[over.match.list]]</a>
542
 
543
+ When objects of non-aggregate class type `T` are list-initialized such
544
+ that [[dcl.init.list]] specifies that overload resolution is performed
545
+ according to the rules in this section, overload resolution selects the
546
+ constructor in two phases:
547
 
548
  - Initially, the candidate functions are the initializer-list
549
  constructors ([[dcl.init.list]]) of the class `T` and the argument
550
  list consists of the initializer list as a single argument.
551
  - If no viable initializer-list constructor is found, overload
 
554
  the elements of the initializer list.
555
 
556
  If the initializer list has no elements and `T` has a default
557
  constructor, the first phase is omitted. In copy-list-initialization, if
558
  an `explicit` constructor is chosen, the initialization is ill-formed.
559
+
560
+ [*Note 1*: This differs from other situations ([[over.match.ctor]], 
561
  [[over.match.copy]]), where only converting constructors are considered
562
  for copy-initialization. This restriction only applies if this
563
+ initialization is part of the final result of overload
564
+ resolution. — *end note*]
565
+
566
+ #### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
567
+
568
+ A set of functions and function templates is formed comprising:
569
+
570
+ - For each constructor of the primary class template designated by the
571
+ *template-name*, if the template is defined, a function template with
572
+ the following properties:
573
+ - The template parameters are the template parameters of the class
574
+ template followed by the template parameters (including default
575
+ template arguments) of the constructor, if any.
576
+ - The types of the function parameters are those of the constructor.
577
+ - The return type is the class template specialization designated by
578
+ the *template-name* and template arguments corresponding to the
579
+ template parameters obtained from the class template.
580
+ - If the primary class template `C` is not defined or does not declare
581
+ any constructors, an additional function template derived as above
582
+ from a hypothetical constructor `C()`.
583
+ - An additional function template derived as above from a hypothetical
584
+ constructor `C(C)`, called the *copy deduction candidate*.
585
+ - For each *deduction-guide*, a function or function template with the
586
+ following properties:
587
+ - The template parameters, if any, and function parameters are those
588
+ of the *deduction-guide*.
589
+ - The return type is the *simple-template-id* of the
590
+ *deduction-guide*.
591
+
592
+ Initialization and overload resolution are performed as described in
593
+ [[dcl.init]] and [[over.match.ctor]], [[over.match.copy]], or
594
+ [[over.match.list]] (as appropriate for the type of initialization
595
+ performed) for an object of a hypothetical class type, where the
596
+ selected functions and function templates are considered to be the
597
+ constructors of that class type for the purpose of forming an overload
598
+ set, and the initializer is provided by the context in which class
599
+ template argument deduction was performed. Each such notional
600
+ constructor is considered to be explicit if the function or function
601
+ template was generated from a constructor or *deduction-guide* that was
602
+ declared `explicit`. All such notional constructors are considered to be
603
+ public members of the hypothetical class type.
604
+
605
+ [*Example 1*:
606
+
607
+ ``` cpp
608
+ template <class T> struct A {
609
+ explicit A(const T&, ...) noexcept; // #1
610
+ A(T&&, ...); // #2
611
+ };
612
+
613
+ int i;
614
+ A a1 = { i, i }; // error: explicit constructor #1 selected in copy-list-initialization during deduction,
615
+ // cannot deduce from non-forwarding rvalue reference in #2
616
+
617
+ A a2{i, i}; // OK, #1 deduces to A<int> and also initializes
618
+ A a3{0, i}; // OK, #2 deduces to A<int> and also initializes
619
+ A a4 = {0, i}; // OK, #2 deduces to A<int> and also initializes
620
+
621
+ template <class T> A(const T&, const T&) -> A<T&>; // #3
622
+ template <class T> explicit A(T&&, T&&) -> A<T>; // #4
623
+
624
+ A a5 = {0, 1}; // error: explicit deduction guide #4 selected in copy-list-initialization during deduction
625
+ A a6{0,1}; // OK, #4 deduces to A<int> and #2 initializes
626
+ A a7 = {0, i}; // error: #3 deduces to A<int&>, #1 and #2 declare same constructor
627
+ A a8{0,i}; // error: #3 deduces to A<int&>, #1 and #2 declare same constructor
628
+
629
+ template <class T> struct B {
630
+ template <class U> using TA = T;
631
+ template <class U> B(U, TA<U>);
632
+ };
633
+
634
+ B b{(int*)0, (char*)0}; // OK, deduces B<char*>
635
+ ```
636
+
637
+ — *end example*]
638