From Jason Turner

[over.match.funcs]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp85zwls5o/{from.md → to.md} +96 -66
tmp/tmp85zwls5o/{from.md → to.md} RENAMED
@@ -31,12 +31,12 @@ parameter is
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 `&&`
34
  *ref-qualifier*
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
 
@@ -188,63 +188,80 @@ 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
204
- primary-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
@@ -277,10 +294,19 @@ void d() {
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
 
@@ -307,11 +333,11 @@ returning `R`”, or the type “reference to function of (`P₁`, …, `Pₙ`)
307
  returning `R`”, a *surrogate call function* with the unique name
308
  *call-function* and having the form
309
 
310
  ``` bnf
311
  'R' *call-function* '(' conversion-type-id \ %
312
- 'F, P₁ a₁, …, Pₙ aₙ)' '{ return F (a₁, …, aₙ); }'
313
  ```
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`
@@ -390,14 +416,14 @@ However, the operands are sequenced in the order prescribed for the
390
  built-in operator [[expr.compound]].
391
 
392
  **Table: Relationship between operator and function call notation** <a id="over.match.oper">[over.match.oper]</a>
393
 
394
  | Subclause | Expression | As member function | As non-member function |
395
- | ------------ | ---------- | ------------------- | ---------------------- |
396
  | (a)} |
397
  | (a, b)} |
398
- | [[over.ass]] | `a=b` | `(a).operator= (b)` | |
399
  | [[over.sub]] | `a[b]` | `(a).operator[](b)` | |
400
  | [[over.ref]] | `a->` | `(a).operator->( )` | |
401
  | (a, 0)} |
402
 
403
 
@@ -494,16 +520,12 @@ inline namespace N {
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
504
- a type match with the left-most parameter of a built-in candidate.
505
 
506
  For all other operators, no such restrictions apply.
507
 
508
  The set of candidate functions for overload resolution for some operator
509
  `@` is the union of the member candidates, the non-member candidates,
@@ -612,17 +634,18 @@ void B::f() {
612
 
613
  When objects of class type are direct-initialized [[dcl.init]],
614
  copy-initialized from an expression of the same or a derived class type
615
  [[dcl.init]], or default-initialized [[dcl.init]], overload resolution
616
  selects the constructor. For direct-initialization or
617
- default-initialization that is not in the context of
618
- copy-initialization, the candidate functions are all the constructors of
619
- the class of the object being initialized. For copy-initialization
620
- (including default initialization in the context of
621
- copy-initialization), the candidate functions are all the converting
622
- constructors [[class.conv.ctor]] of that class. The argument list is the
623
- *expression-list* or *assignment-expression* of the *initializer*.
 
624
 
625
  #### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
626
 
627
  Under the conditions specified in  [[dcl.init]], as part of a
628
  copy-initialization of an object of class type, a user-defined
@@ -635,11 +658,11 @@ to a possibly cv-qualified class type is determined in terms of a
635
  corresponding non-reference copy-initialization. — *end note*]
636
 
637
  Assuming that “*cv1* `T`” is the type of the object being initialized,
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
@@ -686,14 +709,13 @@ 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
@@ -726,40 +748,47 @@ resolution selects the constructor in two phases:
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
740
- class template `C`, a set of functions and function templates, called
741
- the guides of `C`, is formed comprising:
 
742
 
743
  - If `C` is defined, for each constructor of `C`, a function template
744
  with the following properties:
745
  - The template parameters are the template parameters of `C` followed
746
  by the template parameters (including default template arguments) of
747
  the constructor, if any.
748
- - The types of the function parameters are those of the constructor.
 
 
 
 
 
 
749
  - The return type is the class template specialization designated by
750
  `C` and template arguments corresponding to the template parameters
751
  of `C`.
752
  - If `C` is not defined or does not declare any constructors, an
753
  additional function template derived as above from a hypothetical
754
  constructor `C()`.
755
  - An additional function template derived as above from a hypothetical
756
  constructor `C(C)`, called the *copy deduction candidate*.
757
  - For each *deduction-guide*, a function or function template with the
758
  following properties:
759
- - The template parameters, if any, and function parameters are those
760
- of the *deduction-guide*.
761
  - The return type is the *simple-template-id* of the
762
  *deduction-guide*.
763
 
764
  In addition, if `C` is defined and its definition satisfies the
765
  conditions for an aggregate class [[dcl.init.aggr]] with the assumption
@@ -819,11 +848,11 @@ 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*:
@@ -876,12 +905,13 @@ J j = { "ghi" }; // error: cannot bind reference to array of unsigned char to
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
 
884
  ``` bnf
885
  typenameₒₚₜ nested-name-specifierₒₚₜ templateₒₚₜ simple-template-id
886
  ```
887
 
 
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 `&&`
34
  *ref-qualifier*
35
 
36
+ where `X` is the class of which the function is a direct member and cv
37
+ is the 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
 
 
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 designated 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* or
197
+ *splice-expression* that designates one or more functions. Such a
198
+ *postfix-expression*, perhaps nested arbitrarily deep in parentheses,
199
+ has one of the following forms:
200
 
201
  ``` bnf
202
  postfix-expression:
203
  postfix-expression '.' id-expression
204
+ postfix-expression '.' splice-expression
205
  postfix-expression '->' id-expression
206
+ postfix-expression '->' splice-expression
207
+ id-expression
208
+ splice-expression
209
  ```
210
 
211
  These represent two syntactic subcategories of function calls: qualified
212
  function calls and unqualified function calls.
213
 
214
+ In qualified function calls, the function is designated by an
215
+ *id-expression* or *splice-expression* E preceded by an `->` or `.`
216
+ operator. Since the construct `A->B` is generally equivalent to
217
+ `(*A).B`, the rest of [[over]] assumes, without loss of generality, that
218
+ all member function calls have been normalized to the form that uses an
219
+ object and the `.` operator. Furthermore, [[over]] assumes that the
220
+ *postfix-expression* that is the left operand of the `.` operator has
221
+ type “cv `T`” where `T` denotes a class.[^2]
222
 
223
+ The set of candidate functions either is the set found by name lookup
224
+ [[class.member.lookup]] if E is an *id-expression* or is the set
225
+ determined as specified in  [[expr.prim.splice]] if E is a
226
+ *splice-expression*. The argument list is the *expression-list* in the
227
+ call augmented by the addition of the left operand of the `.` operator
228
+ in the normalized member function call as the implied object argument
229
+ [[over.match.funcs]].
230
 
231
+ In unqualified function calls, the function is designated by an
232
+ *id-expression* or a *splice-expression* E. The set of candidate
233
+ functions either is the set found by name lookup [[basic.lookup]] if E
234
+ is an *id-expression* or is the set determined as specified in 
235
+ [[expr.prim.splice]] if E is a *splice-expression*. The set of candidate
236
+ functions consists either entirely of non-member functions or entirely
237
+ of member functions of some class `T`. In the former case or if E is
238
+ either a *splice-expression* or the address of an overload set, the
239
+ argument list is the same as the *expression-list* in the call.
240
+ Otherwise, the argument list is the *expression-list* in the call
241
+ augmented by the addition of an implied object argument as in a
242
+ qualified function call. If the current class is, or is derived from,
243
+ `T`, and the keyword `this` [[expr.prim.this]] refers to it,
244
 
245
+ - if the unqualified function call appears in a precondition assertion
246
+ of a constructor or a postcondition assertion of a destructor and
247
+ overload resolution selects a non-static member function, the call is
248
+ ill-formed;
249
+ - otherwise, the implied object argument is `(*this)`.
250
+
251
+ Otherwise,
252
+
253
+ - if overload resolution selects a non-static member function, the call
254
+ is ill-formed;
255
+ - otherwise, a contrived object of type `T` becomes the implied object
256
+ argument.[^3]
257
 
258
  [*Example 1*:
259
 
260
  ``` cpp
261
  struct C {
262
+ bool a();
263
  void b() {
264
  a(); // OK, (*this).a()
265
  }
266
 
267
  void c(this const C&); // #1
 
294
  void k(this int);
295
  operator int() const;
296
  void m(this const C& c) {
297
  c.k(); // OK
298
  }
299
+
300
+ C()
301
+ pre(a()) // error: implied this in constructor precondition
302
+ pre(this->a()) // OK
303
+ post(a()); // OK
304
+ ~C()
305
+ pre(a()) // OK
306
+ post(a()) // error: implied this in destructor postcondition
307
+ post(this->a()); // OK
308
  };
309
  ```
310
 
311
  — *end example*]
312
 
 
333
  returning `R`”, a *surrogate call function* with the unique name
334
  *call-function* and having the form
335
 
336
  ``` bnf
337
  'R' *call-function* '(' conversion-type-id \ %
338
+ 'F, P₁ a₁, …, Pₙ aₙ)' '{' return 'F (a₁, …, aₙ); }'
339
  ```
340
 
341
  is also considered as a candidate function. Similarly, surrogate call
342
  functions are added to the set of candidate functions for each
343
  non-explicit conversion function declared in a base class of `T`
 
416
  built-in operator [[expr.compound]].
417
 
418
  **Table: Relationship between operator and function call notation** <a id="over.match.oper">[over.match.oper]</a>
419
 
420
  | Subclause | Expression | As member function | As non-member function |
421
+ | --------------- | ---------- | ------------------- | ---------------------- |
422
  | (a)} |
423
  | (a, b)} |
424
+ | [[over.assign]] | `a=b` | `(a).operator= (b)` | |
425
  | [[over.sub]] | `a[b]` | `(a).operator[](b)` | |
426
  | [[over.ref]] | `a->` | `(a).operator->( )` | |
427
  | (a, 0)} |
428
 
429
 
 
520
  bool d1 = 0 == D(); // OK, calls reversed #4; #5 does not forbid #4 as a rewrite target
521
  ```
522
 
523
  — *end example*]
524
 
525
+ For the first parameter of the built-in assignment operators, only
526
+ standard conversion sequences [[over.ics.scs]] are considered.
 
 
 
 
527
 
528
  For all other operators, no such restrictions apply.
529
 
530
  The set of candidate functions for overload resolution for some operator
531
  `@` is the union of the member candidates, the non-member candidates,
 
634
 
635
  When objects of class type are direct-initialized [[dcl.init]],
636
  copy-initialized from an expression of the same or a derived class type
637
  [[dcl.init]], or default-initialized [[dcl.init]], overload resolution
638
  selects the constructor. For direct-initialization or
639
+ default-initialization (including default-initialization in the context
640
+ of copy-list-initialization), the candidate functions are all the
641
+ constructors of the class of the object being initialized. Otherwise,
642
+ the candidate functions are all the non-explicit constructors
643
+ [[class.conv.ctor]] of that class. The argument list is the
644
+ *expression-list* or *assignment-expression* of the *initializer*. For
645
+ default-initialization in the context of copy-list-initialization, if an
646
+ explicit constructor is chosen, the initialization is ill-formed.
647
 
648
  #### Copy-initialization of class by user-defined conversion <a id="over.match.copy">[[over.match.copy]]</a>
649
 
650
  Under the conditions specified in  [[dcl.init]], as part of a
651
  copy-initialization of an object of class type, a user-defined
 
658
  corresponding non-reference copy-initialization. — *end note*]
659
 
660
  Assuming that “*cv1* `T`” is the type of the object being initialized,
661
  with `T` a class type, the candidate functions are selected as follows:
662
 
663
+ - The non-explicit constructors [[class.conv.ctor]] of `T` are candidate
664
  functions.
665
  - When the type of the initializer expression is a class type “cv `S`”,
666
  conversion functions are considered. The permissible types for
667
  non-explicit conversion functions are `T` and any class derived from
668
  `T`. When initializing a temporary object [[class.mem]] to be bound to
 
709
  conversion function to be invoked. Assuming that “reference to *cv1*
710
  `T`” is the type of the reference being initialized, the candidate
711
  functions are selected as follows:
712
 
713
  - Let R be a set of types including
714
+ - “lvalue reference to *cv2* `T2`” (when converting to an lvalue) and
715
+ - “*cv2* `T2`” and “rvalue reference to *cv2* `T2`” (when converting
716
+ to an rvalue or an lvalue of function type)
 
717
 
718
  for any `T2`. The permissible types for non-explicit conversion
719
  functions are the members of R where “*cv1* `T`” is
720
  reference-compatible [[dcl.init.ref]] with “*cv2* `T2`”. For
721
  direct-initialization, the permissible types for explicit conversion
 
748
 
749
  In copy-list-initialization, if an explicit constructor is chosen, the
750
  initialization is ill-formed.
751
 
752
  [*Note 1*: This differs from other situations
753
+ [[over.match.ctor]], [[over.match.copy]], where only non-explicit
754
  constructors are considered for copy-initialization. This restriction
755
  only applies if this initialization is part of the final result of
756
  overload resolution. — *end note*]
757
 
758
  #### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
759
 
760
  When resolving a placeholder for a deduced class type
761
+ [[dcl.type.class.deduct]] where the *template-name* or
762
+ *splice-type-specifier* designates a primary class template `C`, a set
763
+ of functions and function templates, called the guides of `C`, is formed
764
+ comprising:
765
 
766
  - If `C` is defined, for each constructor of `C`, a function template
767
  with the following properties:
768
  - The template parameters are the template parameters of `C` followed
769
  by the template parameters (including default template arguments) of
770
  the constructor, if any.
771
+ - The associated constraints [[temp.constr.decl]] are the conjunction
772
+ of the associated constraints of `C` and the associated constraints
773
+ of the constructor, if any. \[*Note 1*: A *constraint-expression* in
774
+ the *template-head* of `C` is checked for satisfaction before any
775
+ constraints from the *template-head* or trailing *requires-clause*
776
+ of the constructor. — *end note*]
777
+ - The *parameter-declaration-clause* is that of the constructor.
778
  - The return type is the class template specialization designated by
779
  `C` and template arguments corresponding to the template parameters
780
  of `C`.
781
  - If `C` is not defined or does not declare any constructors, an
782
  additional function template derived as above from a hypothetical
783
  constructor `C()`.
784
  - An additional function template derived as above from a hypothetical
785
  constructor `C(C)`, called the *copy deduction candidate*.
786
  - For each *deduction-guide*, a function or function template with the
787
  following properties:
788
+ - The *template-head*, if any, and *parameter-declaration-clause* are
789
+ those of the *deduction-guide*.
790
  - The return type is the *simple-template-id* of the
791
  *deduction-guide*.
792
 
793
  In addition, if `C` is defined and its definition satisfies the
794
  conditions for an aggregate class [[dcl.init.aggr]] with the assumption
 
848
  template argument list is a specialization of `A` with the template
849
  argument list of `A` [[temp.dep.type]] having a member typedef `type`
850
  designating a template specialization with the template argument list of
851
  `A` but with `C` as the template.
852
 
853
+ [*Note 2*: Equivalently, the template parameter list of the
854
  specialization is that of `C`, the template argument list of the
855
  specialization is `B`, and the member typedef names `C` with the
856
  template argument list of `C`. — *end note*]
857
 
858
  [*Example 1*:
 
905
  ```
906
 
907
  — *end example*]
908
 
909
  When resolving a placeholder for a deduced class type
910
+ [[dcl.type.simple]] where the *template-name* or *splice-type-specifier*
911
+ designates an alias template `A`, the *defining-type-id* of `A` must be
912
+ of the form
913
 
914
  ``` bnf
915
  typenameₒₚₜ nested-name-specifierₒₚₜ templateₒₚₜ simple-template-id
916
  ```
917