The function call with the address of the overload set is rejected by both Clang and GCC

Viewed 141

Consider this example

struct A{
    static void fun(int){}
    void fun(double){}
    void show(){
        (&A::fun)(0);   //#1 ill-formed
        //A::fun(0);    //#2 OK
    }
};
int main() {
   A::fun(0);
}

#2 is accepted by GCC and Clang while #1 is rejected by both. It appears to me that they should have the same treatment. My reason is, as per [over.match.call#general-2]

If the postfix-expression is the address of an overload set, overload resolution is applied using that set as described above. If the function selected by overload resolution is a non-static member function, the program is ill-formed.

For &A::fun, its overload set is defined in [over.over#2]

If there is no target, all non-template functions named are selected.

That means the overload set consists of the static and non-static member function of class A. Obviously, the static member function is better than the non-static member function with the argument of type int.

Hence, it violates neither

If the function selected by overload resolution is a non-static member function, the program is ill-formed.

nor

Otherwise, a contrived object of type T becomes the implied object argument;112 if overload resolution selects a non-static member function, the call is ill-formed.

I wonder that, Are both GCC and Clang wrong on this example?

0 Answers
Related