enumerators of `enum` definition with *nested-name-specifier* are injected into the wrong scope
Clang accepts this:
namespace N {
enum E : int;
}
enum N::E : int { A };
auto a = A;
auto b = N::A;
... even though it seems clear that the name A should only be introduced in namespace N and not in the global namespace.
The language rules also seem to get this wrong, saying that A should be introduced only in the global namespace and not in N:
[dcl.enum]/12: The name of each unscoped enumerator is also bound in the scope that immediately contains the enum-specifier.
... but that seems to be a bug in the language rules.
GCC, MSVC, and EDG all do the "obvious" thing and introduce the name A in namespace N only.
@llvm/issue-subscribers-clang-codegen
Author: Richard Smith (zygoloid)
namespace N {
enum E : int;
}
enum N::E : int { A };
auto a = A;
auto b = N::A;
... even though it seems clear that the name A should only be introduced in namespace N and not in the global namespace.
The language rules also seem to get this wrong, saying that A should be introduced only in the global namespace and not in N:
> [dcl.enum]/12: The name of each unscoped enumerator is also bound in the scope that immediately contains the enum-specifier.
... but that seems to be a bug in the language rules.
GCC, MSVC, and EDG all do the "obvious" thing and introduce the name A in namespace N only.
See also: https://github.com/llvm/llvm-project/issues/34749 https://github.com/llvm/llvm-project/issues/45690