The C++14 (precisely, N4296) says with respect to enumerations, in 7.2:11:
Each enum-name and each unscoped enumerator is declared in the scope that immediately contains the enum-specifier.
Now what happens if a namespace N contains an opaque-enum-declaration of an enum E, and later the enumeration is fully declared from the global namespace? Shall we find its enumerators in the global namespace, or in the namespace N?
Of course, in order to opaque-declare an unscoped enumeration, it shall have a fixed underlying type. Consider the following piece of code.
namespace N { enum E : int; }
enum N::E : int {A,B};
namespace N {
int foo() {
return int(::N::B);
}
}
int bar() {
//return int(::A);
return int(A);
}
The first line in bar is commented out, because clang++ -std=c++14 says:
no member named 'A' in the global namespace; did you mean simply 'A'?
Gcc fails to compile both lines in bar(). So both gcc and clang declare the enumerations in the namespace N.
So my questions are:
- What is the scope that immediatelly contains the enum specifier? (I thing it is the scope of the global namespace).
- Should the enumerators
A,Bbe defined in the global namespace? - In the
barfunction, why::Adoes not refer to the enumerator, but simpleAdoes? - Why the expression
::N::Bin the functionN::foodenotes the enumerator?
EDIT 1: the original declaration was enum ::N::E : int {A,B};, but gcc was not able to parse it (bug report), so I removed the leading colons to use enum N::E : int {A,B};
EDIT 2: the clang's behavior is a bug