From Jason Turner

[over.call.func]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp38o69q1o/{from.md → to.md} +79 -38
tmp/tmp38o69q1o/{from.md → to.md} RENAMED
@@ -1,12 +1,11 @@
1
  ##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
2
 
3
  Of interest in  [[over.call.func]] are only those function calls in
4
- which the *postfix-expression* ultimately contains a name that denotes
5
- one or more functions that might be called. Such a *postfix-expression*,
6
- perhaps nested arbitrarily deep in parentheses, has one of the following
7
- forms:
8
 
9
  ``` bnf
10
  postfix-expression:
11
  postfix-expression '.' id-expression
12
  postfix-expression '->' id-expression
@@ -14,40 +13,82 @@ postfix-expression:
14
  ```
15
 
16
  These represent two syntactic subcategories of function calls: qualified
17
  function calls and unqualified function calls.
18
 
19
- In qualified function calls, the name to be resolved is an
20
- *id-expression* and is preceded by an `->` or `.` operator. Since the
21
- construct `A->B` is generally equivalent to `(*A).B`, the rest of
22
- [[over]] assumes, without loss of generality, that all member function
23
- calls have been normalized to the form that uses an object and the `.`
24
- operator. Furthermore, [[over]] assumes that the *postfix-expression*
25
- that is the left operand of the `.` operator has type “cv `T`” where `T`
26
- denotes a class.[^3] Under this assumption, the *id-expression* in the
27
- call is looked up as a member function of `T` following the rules for
28
- looking up names in classes [[class.member.lookup]]. The function
29
- declarations found by that lookup constitute the set of candidate
30
- functions. The argument list is the *expression-list* in the call
31
- augmented by the addition of the left operand of the `.` operator in the
32
- normalized member function call as the implied object argument
33
- [[over.match.funcs]].
34
-
35
- In unqualified function calls, the name is not qualified by an `->` or
36
- `.` operator and has the more general form of a *primary-expression*.
37
- The name is looked up in the context of the function call following the
38
- normal rules for name lookup in expressions [[basic.lookup]]. The
39
- function declarations found by that lookup constitute the set of
40
- candidate functions. Because of the rules for name lookup, the set of
41
- candidate functions consists (1) entirely of non-member functions or (2)
42
- entirely of member functions of some class `T`. In case (1), the
43
- argument list is the same as the *expression-list* in the call. In case
44
- (2), the argument list is the *expression-list* in the call augmented by
45
- the addition of an implied object argument as in a qualified function
46
- call. If the keyword `this` [[class.this]] is in scope and refers to
47
- class `T`, or a derived class of `T`, then the implied object argument
48
- is `(*this)`. If the keyword `this` is not in scope or refers to another
49
- class, then a contrived object of type `T` becomes the implied object
50
- argument.[^4] If the argument list is augmented by a contrived object
51
- and overload resolution selects one of the non-static member functions
52
- of `T`, the call is ill-formed.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
 
1
  ##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
2
 
3
  Of interest in  [[over.call.func]] are only those function calls in
4
+ which the *postfix-expression* ultimately contains an *id-expression*
5
+ that denotes one or more functions. Such a *postfix-expression*, perhaps
6
+ nested arbitrarily deep in parentheses, has one of the following forms:
 
7
 
8
  ``` bnf
9
  postfix-expression:
10
  postfix-expression '.' id-expression
11
  postfix-expression '->' id-expression
 
13
  ```
14
 
15
  These represent two syntactic subcategories of function calls: qualified
16
  function calls and unqualified function calls.
17
 
18
+ In qualified function calls, the function is named by an *id-expression*
19
+ preceded by an `->` or `.` operator. Since the construct `A->B` is
20
+ generally equivalent to `(*A).B`, the rest of [[over]] assumes, without
21
+ loss of generality, that all member function calls have been normalized
22
+ to the form that uses an object and the `.` operator. Furthermore,
23
+ [[over]] assumes that the *postfix-expression* that is the left operand
24
+ of the `.` operator has type “cv `T`” where `T` denotes a class.[^2]
25
+
26
+ The function declarations found by name lookup [[class.member.lookup]]
27
+ constitute the set of candidate functions. The argument list is the
28
+ *expression-list* in the call augmented by the addition of the left
29
+ operand of the `.` operator in the normalized member function call as
30
+ the implied object argument [[over.match.funcs]].
31
+
32
+ In unqualified function calls, the function is named by a
33
+ *primary-expression*. The function declarations found by name lookup
34
+ [[basic.lookup]] constitute the set of candidate functions. Because of
35
+ the rules for name lookup, the set of candidate functions consists
36
+ either entirely of non-member functions or entirely of member functions
37
+ of some class `T`. In the former case or if the *primary-expression* is
38
+ the address of an overload set, the argument list is the same as the
39
+ *expression-list* in the call. Otherwise, the argument list is the
40
+ *expression-list* in the call augmented by the addition of an implied
41
+ object argument as in a qualified function call. If the current class
42
+ is, or is derived from, `T`, and the keyword `this` [[expr.prim.this]]
43
+ refers to it, then the implied object argument is `(*this)`. Otherwise,
44
+ a contrived object of type `T` becomes the implied object argument;[^3]
45
+
46
+ if overload resolution selects a non-static member function, the call is
47
+ ill-formed.
48
+
49
+ [*Example 1*:
50
+
51
+ ``` cpp
52
+ struct C {
53
+ void a();
54
+ void b() {
55
+ a(); // OK, (*this).a()
56
+ }
57
+
58
+ void c(this const C&); // #1
59
+ void c()&; // #2
60
+ static void c(int = 0); // #3
61
+
62
+ void d() {
63
+ c(); // error: ambiguous between #2 and #3
64
+ (C::c)(); // error: as above
65
+ (&(C::c))(); // error: cannot resolve address of overloaded this->C::c[over.over]
66
+ (&C::c)(C{}); // selects #1
67
+ (&C::c)(*this); // error: selects #2, and is ill-formed[over.match.call.general]
68
+ (&C::c)(); // selects #3
69
+ }
70
+
71
+ void f(this const C&);
72
+ void g() const {
73
+ f(); // OK, (*this).f()
74
+ f(*this); // error: no viable candidate for (*this).f(*this)
75
+ this->f(); // OK
76
+ }
77
+
78
+ static void h() {
79
+ f(); // error: contrived object argument, but overload resolution
80
+ // picked a non-static member function
81
+ f(C{}); // error: no viable candidate
82
+ C{}.f(); // OK
83
+ }
84
+
85
+ void k(this int);
86
+ operator int() const;
87
+ void m(this const C& c) {
88
+ c.k(); // OK
89
+ }
90
+ };
91
+ ```
92
+
93
+ — *end example*]
94