I'm trying to figure out why major compilers refuse to compile the following example (godbolt):
struct Base
{
void Derived();
};
struct Derived : public Base
{
};
int main()
{
Derived x;
x.Derived(); // Compilation error.
// gcc: Invalid use of Derived::Derived.
// clang: Cannot refer to type member 'Derived' in 'Derived' with '.'
return 0;
}
My question is: what clause in the C++ standard makes the above example ill-formed?
Intuition suggests that the error may have something to do with implicitly declared default constructor Derived::Derived()
. But then, the standard seems pretty clear on this:
[class.ctor]
Constructors do not have names. [...]
Because constructors do not have names, they are never found during unqualified name lookup [...]
My interpretation of that clause is that since constructors don't have names, they can't hide any name in any base class. So, unqualified name Derived
in expression x.Derived
should be resolved to x.Base::Derived
, which seems perfectly callable.
What am I missing or getting wrong?