Question
Overload resolution between ordinary and explicit object member functions
In the following test program, struct B
has two member functions f
, which can be called using B{}.f()
: one ordinary f()
and another with explicit object f(this A)
.
struct A {
int f() { return 1; }
};
struct B : A {
using A::f;
int f(this A) { return 2; }
};
int main() {
return B{}.f();
}
Which function must be selected by overload resolution?
GCC and MSVC prefer ordinary member function f()
and the program returns 1
.
But Clang makes the opposite choice, selecting explicit object member function f(this A)
and the program returns 2
.
Online demo: https://gcc.godbolt.org/z/1bo69Ta8q
Which compiler is correct here if any (why not ambiguity of overload resolution)?