c++ - Overload resolution without a parameter list on class member access? -
struct x { void f(double) {} static void f(int) {} }; int main() { x x; auto y = x.f; } gcc gives:
error: unable deduce ‘auto’ ‘x.x::f’ x.f class member access postfix-expression documented in 5.2.5 [expr.ref]
it says:
if
f(possibly overloaded) member function, function overload resolution (13.3) used deter- mine whetherx.frefers static or non-static member function. (from n3485 5.2.5.4.3 )
how can overload resolution applied here - x.f doesn't have parameter list overload resolution?
or missing something?
update: if change auto y = x.f line expression-statement:
- auto y = x.f; + x.f; then gcc instead complains:
error: statement cannot resolve address of overloaded function
i think you're right in standard isn't precise @ point:
[expr.ref]/4
if f (possibly overloaded) member function, function overload resolution (13.3) used determine whether
x.frefers static or non-static member function.
as first sub-bullet states:
if refers static member function , type of e2 “function of parameter-type-list returning t”, e1.e2 lvalue; expression designates static member function. type of e1.e2 same type of e2, namely “function of parameter-type-list returning t”.
that is, x.f can used initialize function ptr if f static, whereas (see following sub-bullet) if f not static, can used in function-call expression.
but actually, overload resolution is not performed select overload name of overloaded function outside context of function-call-expression:
[over.over]/1
a use of overloaded function name without arguments resolved in contexts function, pointer function or pointer member function specific function overload set. [...] the function selected 1 type identical function type of target type required in context.
that is, exact match, not invoking overload resolution mechanism described in [over.match]. therefore [expr.ref]/4 incomplete, doesn't describe case of using x.f initialize function pointer/reference.
as auto keyword doesn't specify target type (or according [dcl.spec.auto]/6, mechanism deduce type auto fails), cannot use auto y = x.f;:
x.frefers set of overloaded functions- a function set needs selected
- selection based upon overload resolution (in function-call-expression, not applicable here) or based on target type
- there's no target type here, or rather, target type equivalent template argument, therefore type deduction
autofails
the type of x.f therefore is
- in context of function call, directly refer [expr.ref]/4
- otherwise, set of overloaded functions, function selected according [over.over], whereupon type determined according [expr.ref]/4
Comments
Post a Comment