tmp/tmpv07cw_tf/{from.md → to.md}
RENAMED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
#### Function call syntax <a id="over.match.call">[[over.match.call]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
In a function call [[expr.call]]
|
| 4 |
|
| 5 |
``` bnf
|
| 6 |
postfix-expression '(' expression-listₒₚₜ ')'
|
| 7 |
```
|
|
@@ -11,24 +13,27 @@ template, overload resolution is applied as specified in
|
|
| 11 |
[[over.call.func]]. If the *postfix-expression* denotes an object of
|
| 12 |
class type, overload resolution is applied as specified in
|
| 13 |
[[over.call.object]].
|
| 14 |
|
| 15 |
If the *postfix-expression* is the address of an overload set, overload
|
| 16 |
-
resolution is applied using that set as described above.
|
| 17 |
-
selected by overload resolution is a non-static member function, the
|
| 18 |
-
program is ill-formed.
|
| 19 |
|
| 20 |
-
[*Note 1*:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
contexts is described in [[over.over]]. — *end note*]
|
| 22 |
|
| 23 |
##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
|
| 24 |
|
| 25 |
Of interest in [[over.call.func]] are only those function calls in
|
| 26 |
-
which the *postfix-expression* ultimately contains
|
| 27 |
-
one or more functions
|
| 28 |
-
|
| 29 |
-
forms:
|
| 30 |
|
| 31 |
``` bnf
|
| 32 |
postfix-expression:
|
| 33 |
postfix-expression '.' id-expression
|
| 34 |
postfix-expression '->' id-expression
|
|
@@ -36,52 +41,94 @@ postfix-expression:
|
|
| 36 |
```
|
| 37 |
|
| 38 |
These represent two syntactic subcategories of function calls: qualified
|
| 39 |
function calls and unqualified function calls.
|
| 40 |
|
| 41 |
-
In qualified function calls, the
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
##### Call to object of class type <a id="over.call.object">[[over.call.object]]</a>
|
| 77 |
|
| 78 |
If the *postfix-expression* `E` in the function call syntax evaluates to
|
| 79 |
a class object of type “cv `T`”, then the set of candidate functions
|
| 80 |
includes at least the function call operators of `T`. The function call
|
| 81 |
-
operators of `T` are
|
| 82 |
-
|
| 83 |
|
| 84 |
In addition, for each non-explicit conversion function declared in `T`
|
| 85 |
of the form
|
| 86 |
|
| 87 |
``` bnf
|
|
@@ -103,27 +150,23 @@ returning `R`”, a *surrogate call function* with the unique name
|
|
| 103 |
|
| 104 |
is also considered as a candidate function. Similarly, surrogate call
|
| 105 |
functions are added to the set of candidate functions for each
|
| 106 |
non-explicit conversion function declared in a base class of `T`
|
| 107 |
provided the function is not hidden within `T` by another intervening
|
| 108 |
-
declaration.[^
|
| 109 |
|
| 110 |
The argument list submitted to overload resolution consists of the
|
| 111 |
argument expressions present in the function call syntax preceded by the
|
| 112 |
implied object argument `(E)`.
|
| 113 |
|
| 114 |
-
[*Note
|
| 115 |
-
the implied object argument is compared against the
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
conversion function from which the surrogate call function was derived
|
| 120 |
-
will be used in the conversion sequence for that parameter since it
|
| 121 |
-
converts the implied object argument to the appropriate function pointer
|
| 122 |
-
or reference required by that first parameter. — *end note*]
|
| 123 |
|
| 124 |
-
[*Example
|
| 125 |
|
| 126 |
``` cpp
|
| 127 |
int f1(int);
|
| 128 |
int f2(float);
|
| 129 |
typedef int (*fp1)(int);
|
|
|
|
| 1 |
#### Function call syntax <a id="over.match.call">[[over.match.call]]</a>
|
| 2 |
|
| 3 |
+
##### General <a id="over.match.call.general">[[over.match.call.general]]</a>
|
| 4 |
+
|
| 5 |
In a function call [[expr.call]]
|
| 6 |
|
| 7 |
``` bnf
|
| 8 |
postfix-expression '(' expression-listₒₚₜ ')'
|
| 9 |
```
|
|
|
|
| 13 |
[[over.call.func]]. If the *postfix-expression* denotes an object of
|
| 14 |
class type, overload resolution is applied as specified in
|
| 15 |
[[over.call.object]].
|
| 16 |
|
| 17 |
If the *postfix-expression* is the address of an overload set, overload
|
| 18 |
+
resolution is applied using that set as described above.
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
[*Note 1*: No implied object argument is added in this
|
| 21 |
+
case. — *end note*]
|
| 22 |
+
|
| 23 |
+
If the function selected by overload resolution is an implicit object
|
| 24 |
+
member function, the program is ill-formed.
|
| 25 |
+
|
| 26 |
+
[*Note 2*: The resolution of the address of an overload set in other
|
| 27 |
contexts is described in [[over.over]]. — *end note*]
|
| 28 |
|
| 29 |
##### Call to named function <a id="over.call.func">[[over.call.func]]</a>
|
| 30 |
|
| 31 |
Of interest in [[over.call.func]] are only those function calls in
|
| 32 |
+
which the *postfix-expression* ultimately contains an *id-expression*
|
| 33 |
+
that denotes one or more functions. Such a *postfix-expression*, perhaps
|
| 34 |
+
nested arbitrarily deep in parentheses, has one of the following forms:
|
|
|
|
| 35 |
|
| 36 |
``` bnf
|
| 37 |
postfix-expression:
|
| 38 |
postfix-expression '.' id-expression
|
| 39 |
postfix-expression '->' id-expression
|
|
|
|
| 41 |
```
|
| 42 |
|
| 43 |
These represent two syntactic subcategories of function calls: qualified
|
| 44 |
function calls and unqualified function calls.
|
| 45 |
|
| 46 |
+
In qualified function calls, the function is named by an *id-expression*
|
| 47 |
+
preceded by an `->` or `.` operator. Since the construct `A->B` is
|
| 48 |
+
generally equivalent to `(*A).B`, the rest of [[over]] assumes, without
|
| 49 |
+
loss of generality, that all member function calls have been normalized
|
| 50 |
+
to the form that uses an object and the `.` operator. Furthermore,
|
| 51 |
+
[[over]] assumes that the *postfix-expression* that is the left operand
|
| 52 |
+
of the `.` operator has type “cv `T`” where `T` denotes a class.[^2]
|
| 53 |
+
|
| 54 |
+
The function declarations found by name lookup [[class.member.lookup]]
|
| 55 |
+
constitute the set of candidate functions. The argument list is the
|
| 56 |
+
*expression-list* in the call augmented by the addition of the left
|
| 57 |
+
operand of the `.` operator in the normalized member function call as
|
| 58 |
+
the implied object argument [[over.match.funcs]].
|
| 59 |
+
|
| 60 |
+
In unqualified function calls, the function is named by a
|
| 61 |
+
*primary-expression*. The function declarations found by name lookup
|
| 62 |
+
[[basic.lookup]] constitute the set of candidate functions. Because of
|
| 63 |
+
the rules for name lookup, the set of candidate functions consists
|
| 64 |
+
either entirely of non-member functions or entirely of member functions
|
| 65 |
+
of some class `T`. In the former case or if the *primary-expression* is
|
| 66 |
+
the address of an overload set, the argument list is the same as the
|
| 67 |
+
*expression-list* in the call. Otherwise, the argument list is the
|
| 68 |
+
*expression-list* in the call augmented by the addition of an implied
|
| 69 |
+
object argument as in a qualified function call. If the current class
|
| 70 |
+
is, or is derived from, `T`, and the keyword `this` [[expr.prim.this]]
|
| 71 |
+
refers to it, then the implied object argument is `(*this)`. Otherwise,
|
| 72 |
+
a contrived object of type `T` becomes the implied object argument;[^3]
|
| 73 |
+
|
| 74 |
+
if overload resolution selects a non-static member function, the call is
|
| 75 |
+
ill-formed.
|
| 76 |
+
|
| 77 |
+
[*Example 1*:
|
| 78 |
+
|
| 79 |
+
``` cpp
|
| 80 |
+
struct C {
|
| 81 |
+
void a();
|
| 82 |
+
void b() {
|
| 83 |
+
a(); // OK, (*this).a()
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
void c(this const C&); // #1
|
| 87 |
+
void c()&; // #2
|
| 88 |
+
static void c(int = 0); // #3
|
| 89 |
+
|
| 90 |
+
void d() {
|
| 91 |
+
c(); // error: ambiguous between #2 and #3
|
| 92 |
+
(C::c)(); // error: as above
|
| 93 |
+
(&(C::c))(); // error: cannot resolve address of overloaded this->C::c[over.over]
|
| 94 |
+
(&C::c)(C{}); // selects #1
|
| 95 |
+
(&C::c)(*this); // error: selects #2, and is ill-formed[over.match.call.general]
|
| 96 |
+
(&C::c)(); // selects #3
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
void f(this const C&);
|
| 100 |
+
void g() const {
|
| 101 |
+
f(); // OK, (*this).f()
|
| 102 |
+
f(*this); // error: no viable candidate for (*this).f(*this)
|
| 103 |
+
this->f(); // OK
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
static void h() {
|
| 107 |
+
f(); // error: contrived object argument, but overload resolution
|
| 108 |
+
// picked a non-static member function
|
| 109 |
+
f(C{}); // error: no viable candidate
|
| 110 |
+
C{}.f(); // OK
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
void k(this int);
|
| 114 |
+
operator int() const;
|
| 115 |
+
void m(this const C& c) {
|
| 116 |
+
c.k(); // OK
|
| 117 |
+
}
|
| 118 |
+
};
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
— *end example*]
|
| 122 |
|
| 123 |
##### Call to object of class type <a id="over.call.object">[[over.call.object]]</a>
|
| 124 |
|
| 125 |
If the *postfix-expression* `E` in the function call syntax evaluates to
|
| 126 |
a class object of type “cv `T`”, then the set of candidate functions
|
| 127 |
includes at least the function call operators of `T`. The function call
|
| 128 |
+
operators of `T` are the results of a search for the name `operator()`
|
| 129 |
+
in the scope of `T`.
|
| 130 |
|
| 131 |
In addition, for each non-explicit conversion function declared in `T`
|
| 132 |
of the form
|
| 133 |
|
| 134 |
``` bnf
|
|
|
|
| 150 |
|
| 151 |
is also considered as a candidate function. Similarly, surrogate call
|
| 152 |
functions are added to the set of candidate functions for each
|
| 153 |
non-explicit conversion function declared in a base class of `T`
|
| 154 |
provided the function is not hidden within `T` by another intervening
|
| 155 |
+
declaration.[^4]
|
| 156 |
|
| 157 |
The argument list submitted to overload resolution consists of the
|
| 158 |
argument expressions present in the function call syntax preceded by the
|
| 159 |
implied object argument `(E)`.
|
| 160 |
|
| 161 |
+
[*Note 3*: When comparing the call against the function call operators,
|
| 162 |
+
the implied object argument is compared against the object parameter of
|
| 163 |
+
the function call operator. When comparing the call against a surrogate
|
| 164 |
+
call function, the implied object argument is compared against the first
|
| 165 |
+
parameter of the surrogate call function. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
+
[*Example 2*:
|
| 168 |
|
| 169 |
``` cpp
|
| 170 |
int f1(int);
|
| 171 |
int f2(float);
|
| 172 |
typedef int (*fp1)(int);
|