The following namespace definition fails to compile when the first declaration is commented out. If the first declaration of foo
is uncommented, then it compiles just fine.
namespace Y
{
//void foo();
void ::Y::foo(){}
}
The relevant part in the standard (§8.3¶1) says:
When the declarator-id is qualified, the declaration shall refer to a previously declared member
I understand that this rule prevents the introduction of names into other namespaces. I wonder if that rule could be relaxed to allow for qualified-ids referring to the current namespace.
CWG #482 is relevant:
So your code is valid if the first declaration of
foo
is present (as of about 2012; GCC has an open bug report). If not, however, your quoted wording still applies and renders the qualified declaration ill-formed. I see no reason to permit that case; it intuitively implies that the name has been declared already, since qualified name lookup must determine what it refers to.