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
|
| 5 |
-
one or more functions
|
| 6 |
-
|
| 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
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|