The following code
struct Foo{};
struct Bar{};
struct Base {
Foo func1(const Foo , const Bar = Bar{}) const {
return {};
};
};
struct Derived : public Base {
using Base::func1;
Foo func1(const Foo ) const {
return {};
};
};
int main() {
Foo foo;
Derived der;
der.func1(foo);
}
is rejected by ICX and clang, but accepted by GCC (up to 13.1). https://godbolt.org/z/4M3rrs3r4
I think GCC is wrong here. If the two func1s were non-members, GCC would reject the call as ambiguous.
Am I right?
It is a bug of the compiler gcc.
From the C++ 20 (9.9 The using declaration)
and (9.3.4.7 Default arguments)
So for the overload resolution the set of function candidates in the class
Derivedconsists of two functionsand
And such a call
in this case is ambiguous. Either function can be called.