Consider this code:
namespace A
{
int i = 24;
}
namespace B
{
using namespace A;
int i = 11;
int k = i; // finds B::i, no ambiguity
}
§6.4.1 Unqualified name lookup [basic.lookup.unqual]
- The declarations from the namespace nominated by a using-directive become visible in a namespace enclosing the using-directive; see [namespace.udir]. For the purpose of the unqualified name lookup rules described in [basic.lookup.unqual], the declarations from the namespace nominated by the using-directive are considered members of that enclosing namespace.
For me the standard says pretty clear that for the purpose of unqualified name lookup (the i
in int k = i
) the declaration of i
from A
is considered member of B
so i
should be ambiguous in int k = i
, however both gcc
and clang
compile and resolve i
to the local B::i
. I have searched the standard (basic.scope.hiding and namespace.udir) and did not find an exception or a rule to contradict the above one. I have found that for qualified name lookup, but not for unqualified name lookup.
Why is i
unambiguous?