From Jason Turner

[over.match.funcs]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpi5pwq77g/{from.md → to.md} +57 -29
tmp/tmpi5pwq77g/{from.md → to.md} RENAMED
@@ -92,10 +92,14 @@ 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
93
  non-template functions. In such a case, the candidate functions
94
  generated from each function template are combined with the set of
95
  non-template candidate functions.
96
 
 
 
 
 
97
  #### Function call syntax <a id="over.match.call">[[over.match.call]]</a>
98
 
99
  In a function call ([[expr.call]])
100
 
101
  ``` bnf
@@ -178,11 +182,11 @@ operators of `T` are obtained by ordinary lookup of the name
178
 
179
  In addition, for each non-explicit conversion function declared in `T`
180
  of the form
181
 
182
  ``` bnf
183
- 'operator' conversion-type-id '( )' attribute-specifier-seqₒₚₜ cv-qualifier ';'
184
  ```
185
 
186
  where *cv-qualifier* is the same cv-qualification as, or a greater
187
  cv-qualification than, *cv*, and where *conversion-type-id* denotes the
188
  type “pointer to function of (`P1`,...,`Pn)` returning `R`”, or the type
@@ -252,13 +256,13 @@ struct String {
252
  };
253
  String operator + (const String&, const String&);
254
 
255
  void f(void) {
256
  const char* p= "one" + "two"; // ill-formed because neither
257
- // operand has user-defined type
258
  int I = 1 + 1; // Always evaluates to 2 even if
259
- // user-defined types exist which
260
  // would perform the operation.
261
  }
262
  ```
263
 
264
  If either operand has a type that is a class or an enumeration, a
@@ -289,13 +293,14 @@ version is `T1`, and for a binary operator `@` with a left operand of a
289
  type whose cv-unqualified version is `T1` and a right operand of a type
290
  whose cv-unqualified version is `T2`, three sets of candidate functions,
291
  designated *member candidates*, *non-member candidates* and *built-in
292
  candidates*, are constructed as follows:
293
 
294
- - If `T1` is a complete class type, the set of member candidates is the
295
- result of the qualified lookup of `T1::operator@` (
296
- [[over.call.func]]); otherwise, the set of member candidates is empty.
 
297
  - The set of non-member candidates is the result of the unqualified
298
  lookup of `operator@` in the context of the expression according to
299
  the usual rules for name lookup in unqualified function calls (
300
  [[basic.lookup.argdep]]) except that all member functions are ignored.
301
  However, if no operand has a class type, only those non-member
@@ -310,12 +315,12 @@ candidates*, are constructed as follows:
310
  defined in  [[over.built]] that, compared to the given operator,
311
  - have the same operator name, and
312
  - accept the same number of operands, and
313
  - accept operand types to which the given operand or operands can be
314
  converted according to [[over.best.ics]], and
315
- - do not have the same parameter-type-list as any non-template
316
- non-member candidate.
317
 
318
  For the built-in assignment operators, conversions of the left operand
319
  are restricted as follows:
320
 
321
  - no temporaries are introduced to hold the left operand, and
@@ -341,15 +346,30 @@ void m() {
341
  a + b; // operator+(a,b) chosen over int(a) + int(b)
342
  }
343
  ```
344
 
345
  If a built-in candidate is selected by overload resolution, the operands
346
- are converted to the types of the corresponding parameters of the
347
- selected operation function. Then the operator is treated as the
 
 
348
  corresponding built-in operator and interpreted according to Clause 
349
  [[expr]].
350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
  The second operand of operator `->` is ignored in selecting an
352
  `operator->` function, and is not an argument when the `operator->`
353
  function is called. When `operator->` returns, the operator `->` is
354
  applied to the value returned, with the original second operand.[^7]
355
 
@@ -394,29 +414,32 @@ the candidate functions are all the converting constructors (
394
 
395
  Under the conditions specified in  [[dcl.init]], as part of a
396
  copy-initialization of an object of class type, a user-defined
397
  conversion can be invoked to convert an initializer expression to the
398
  type of the object being initialized. Overload resolution is used to
399
- select the user-defined conversion to be invoked. Assuming that “*cv1*
400
- `T`” is the type of the object being initialized, with `T` a class type,
401
- the candidate functions are selected as follows:
 
 
 
402
 
403
  - The converting constructors ([[class.conv.ctor]]) of `T` are
404
  candidate functions.
405
  - When the type of the initializer expression is a class type “*cv*
406
  `S`”, the non-explicit conversion functions of `S` and its base
407
  classes are considered. When initializing a temporary to be bound to
408
  the first parameter of a constructor that takes a reference to
409
  possibly cv-qualified `T` as its first argument, called with a single
410
- argument in the context of direct-initialization, explicit conversion
411
- functions are also considered. Those that are not hidden within `S`
412
- and yield a type whose cv-unqualified version is the same type as `T`
413
- or is a derived class thereof are candidate functions. Conversion
414
- functions that return “reference to `X`” return lvalues or xvalues,
415
- depending on the type of reference, of type `X` and are therefore
416
- considered to yield `X` for this process of selecting candidate
417
- functions.
418
 
419
  In both cases, the argument list has one argument, which is the
420
  initializer expression. This argument will be compared against the first
421
  parameter of the constructors and against the implicit object parameter
422
  of the conversion functions.
@@ -459,18 +482,23 @@ applying a conversion function to an initializer expression. Overload
459
  resolution is used to select the conversion function to be invoked.
460
  Assuming that “*cv1* `T`” is the underlying type of the reference being
461
  initialized, and “*cv* `S`” is the type of the initializer expression,
462
  with `S` a class type, the candidate functions are selected as follows:
463
 
464
- - The conversion functions of `S` and its base classes are considered,
465
- except that for copy-initialization, only the non-explicit conversion
466
- functions are considered. Those that are not hidden within `S` and
467
- yield type “lvalue reference to *cv2* `T2`” (when [[dcl.init.ref]]
468
- requires an lvalue result) or “ `T2`” or rvalue reference to `T2`”
469
- (when [[dcl.init.ref]] requires an rvalue result), where “*cv1* `T`”
470
- is reference-compatible ([[dcl.init.ref]]) with “*cv2* `T2`”, are
471
- 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
 
 
92
  refer to one or more function templates and also to a set of overloaded
93
  non-template functions. In such a case, the candidate functions
94
  generated from each function template are combined with the set of
95
  non-template candidate functions.
96
 
97
+ A defaulted move constructor or assignment operator ([[class.copy]])
98
+ that is defined as deleted is excluded from the set of candidate
99
+ functions in all contexts.
100
+
101
  #### Function call syntax <a id="over.match.call">[[over.match.call]]</a>
102
 
103
  In a function call ([[expr.call]])
104
 
105
  ``` bnf
 
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
 
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
 
293
  type whose cv-unqualified version is `T1` and a right operand of a type
294
  whose cv-unqualified version is `T2`, three sets of candidate functions,
295
  designated *member candidates*, *non-member candidates* and *built-in
296
  candidates*, are constructed as follows:
297
 
298
+ - If `T1` is a complete class type or a class currently being defined,
299
+ the set of member candidates is the result of the qualified lookup of
300
+ `T1::operator@` ([[over.call.func]]); otherwise, the set of member
301
+ candidates is empty.
302
  - The set of non-member candidates is the result of the unqualified
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
 
315
  defined in  [[over.built]] that, compared to the given operator,
316
  - have the same operator name, and
317
  - accept the same number of operands, and
318
  - accept operand types to which the given operand or operands can be
319
  converted according to [[over.best.ics]], and
320
+ - do not have the same parameter-type-list as any non-member candidate
321
+ that is not a function template specialization.
322
 
323
  For the built-in assignment operators, conversions of the left operand
324
  are restricted as follows:
325
 
326
  - no temporaries are introduced to hold the left operand, and
 
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
+
363
+ struct Y {
364
+ operator int*();
365
+ };
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
 
 
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.
 
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