llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

enumerators of `enum` definition with *nested-name-specifier* are injected into the wrong scope

Open zygoloid opened this issue 3 years ago • 2 comments

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.

zygoloid avatar Nov 29 '23 19:11 zygoloid

@llvm/issue-subscribers-clang-codegen

Author: Richard Smith (zygoloid)

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.

llvmbot avatar Nov 29 '23 19:11 llvmbot

See also: https://github.com/llvm/llvm-project/issues/34749 https://github.com/llvm/llvm-project/issues/45690

MagentaTreehouse avatar Mar 08 '26 14:03 MagentaTreehouse