[over.match.call] (original) (raw)
12 Overloading [over]
12.2 Overload resolution [over.match]
12.2.2 Candidate functions and argument lists [over.match.funcs]
12.2.2.2 Function call syntax [over.match.call]
12.2.2.2.1 General [over.match.call.general]
If the postfix-expression denotes an object of class type, overload resolution is applied as specified in [over.call.object].
If the postfix-expression is the address of an overload set, overload resolution is applied using that set as described above.
[Note 1:
No implied object argument is added in this case.
— _end note_]
If the function selected by overload resolution is an implicit object member function, the program is ill-formed.
[Note 2:
The resolution of the address of an overload set in other contexts is described in [over.over].
— _end note_]
12.2.2.2.2 Call to named function [over.call.func]
Of interest in [over.call.func] are only those function calls in which the postfix-expressionultimately contains an id-expression that denotes one or more functions.
Such apostfix-expression, perhaps nested arbitrarily deep in parentheses, has one of the following forms:
These represent two syntactic subcategories of function calls: qualified function calls and unqualified function calls.
In qualified function calls, the function is named by an id-expressionpreceded by an -> or . operator.
Since the constructA->Bis generally equivalent to(*A).B, the rest of[over] assumes, without loss of generality, that all member function calls have been normalized to the form that uses an object and the.operator.
Furthermore, [over] assumes that thepostfix-expressionthat is the left operand of the.operator has type “cv T” whereTdenotes a class.100
The function declarations found by name lookup ([class.member.lookup]) constitute the set of candidate functions.
The argument list is theexpression-listin the call augmented by the addition of the left operand of the.operator in the normalized member function call as the implied object argument ([over.match.funcs]).
In unqualified function calls, the function is named by aprimary-expression.
The function declarations found by name lookup ([basic.lookup]) constitute the set of candidate functions.
Because of the rules for name lookup, the set of candidate functions consists either entirely of non-member functions or entirely of member functions of some classT.
In the former case or if the primary-expression is the address of an overload set, the argument list is the same as theexpression-listin the call.
Otherwise, the argument list is theexpression-listin the call augmented by the addition of an implied object argument as in a qualified function call.
If the current class is, or is derived from, T, and the keywordthis ([expr.prim.this]) refers to it,
- if the unqualified function call appears in a precondition assertion of a constructor or a postcondition assertion of a destructor and overload resolution selects a non-static member function, the call is ill-formed;
- otherwise, the implied object argument is(*this).
Otherwise,
- if overload resolution selects a non-static member function, the call is ill-formed;
- otherwise, a contrived object of typeTbecomes the implied object argument.101
[Example 1: struct C { bool a();void b() { a(); } void c(this const C&); void c() &; static void c(int = 0); void d() { c(); (C::c)(); (&(C::c))(); (&C::c)(C{}); (&C::c)(*this); (&C::c)(); } void f(this const C&);void g() const { f(); f(*this); this->f(); } static void h() { f(); f(C{}); C{}.f(); } void k(this int);operator int() const;void m(this const C& c) { c.k(); } C() pre(a()) pre(this->a()) post(a()); ~C() pre(a()) post(a()) post(this->a()); }; — _end example_]
12.2.2.2.3 Call to object of class type [over.call.object]
If the postfix-expression Ein the function call syntax evaluates to a class object of type “cv T”, then the set of candidate functions includes at least the function call operators of T.
The function call operators of Tare the results of a search for the name operator()in the scope of T.
In addition, for each non-explicit conversion function declared in T of the form
where the optionalcv-qualifier-seqis the same cv-qualification as, or a greater cv-qualification than,cv, and whereconversion-type-iddenotes the type “pointer to function of () returning R”, or the type “reference to pointer to function of () returning R”, or the type “reference to function of () returning R”, a surrogate call function with the unique name_call-function_and having the form
R call-function ( conversion-type-id F, P a, …, P a) { return F (a, …, a); }
is also considered as a candidate function.
Similarly, surrogate call functions are added to the set of candidate functions for each non-explicit conversion function declared in a base class ofTprovided the function is not hidden withinTby another intervening declaration.102
The argument list submitted to overload resolution consists of the argument expressions present in the function call syntax preceded by the implied object argument(E).
[Note 1:
When comparing the call against the function call operators, the implied object argument is compared against the object parameter of the function call operator.
When comparing the call against a surrogate call function, the implied object argument is compared against the first parameter of the surrogate call function.
— _end note_]
[Example 1: int f1(int);int f2(float);typedef int (*fp1)(int);typedef int (*fp2)(float);struct A { operator fp1() { return f1; } operator fp2() { return f2; } } a;int i = a(1); — _end example_]