Is this ill-formed or well-formed according to the c++ standard?
namespace M { struct i {}; }
namespace N { static int i = 1; }
using M::i;
using N::i;
int main() { sizeof (i); }
Clang rejects it and GCC accepts it.
According to [namespace.udir-6] (http://eel.is/c++draft/basic.namespace#namespace.udir-6):
If name lookup finds a declaration for a name in two different namespaces, and the declarations do not declare the same entity and do not declare functions, the use of the name is ill-formed.
How should we interpret this? Remember that each using-declaration are declaring a name by [namespace.udecl]p1 (http://eel.is/c++draft/namespace.udecl#1):
A using-declaration introduces a name into the declarative region in which the using-declaration appears.
using-declaration:
using typename
opt nested-name-specifier unqualified-id;
The member name specified in a using-declaration is declared in the declarative region in which the using-declaration appears. [ Note: Only the specified name is so declared; specifying an enumeration name in a using-declaration does not declare its enumerators in the using-declaration's declarative region. — end note ] If a using-declaration names a constructor ([class.qual]), it implicitly declares a set of constructors in the class in which the using-declaration appears ([class.inhctor]); otherwise the name specified in a using-declaration is a synonym for a set of declarations in another namespace or class.
So we have 4 declarations of the name i.
Which of these does unqualified name lookup of i
in sizeof(i)
find?
Does it only find using M::i;
and using N::i;
which are both in the same namespace (the global namespace) so the program is well-formed?
Or does it only find struct i {};
and static int i = 1;
which are in different namespaces so the program is ill-formed?
Or do we have some other alternative?