c++ - §7.1.6.3/1 (C++14) doesn't accept the construction in the second snippet below. Why is this? -


first part:

i'm studying in detail opaque-enum-declarations , elaborated-type-specifiers few days already, , confirm this. gcc , vs2013 don't compile code (clang does) , believe clang in accordance §7.1.6.3/1, enum e elaborated-type-specifier not sole constituent of declaration enum e e = e::b;. analysis correct?

#include <iostream> enum class e : char {a = 'a', b}; int e; enum e e = e::b;        // doesn't compile in gcc , vs2013 int main() {     std::cout << (char)(e) << '\n'; } 

second part:

the snippet below, similar 1 above, doesn't compile. understand why doesn't (the elaborated-type-specifier enum e sole constituent of declaration enum e; , §7.1.6.3/1 doesn't allow this). i'd know why can't compiler accept construction?

#include <iostream> enum class e : char {a = 'a', b}; int e; enum e;                 // doesn't compile. e e = e::b;         int main() {     std::cout << (char)(e) << '\n'; } 

n4140 [basic.scope.hiding]/2:

a class name (9.1) or enumeration name (7.2) can hidden name of variable, data member, function, or enumerator declared in same scope. if class or enumeration name , variable, data member, function, or enumerator declared in same scope (in order) same name, class or enumeration name hidden wherever variable, data member, function, or enumerator name visible.

it appear the declaration of int e hides name of enumeration e in global scope after int's point of declaration. however, name e::b qualified-id nested-name-specifier of e::, rules qualified name lookup apply. in particular, [basic.lookup.qual]/1:

the name of class or namespace member or enumerator can referred after :: scope resolution operator (5.1) applied nested-name-specifier denotes class, namespace, or enumeration. if :: scope resolution operator in nested-name-specifier not preceded decltype-specifier, lookup of name preceding :: considers namespaces, types, , templates specializations types. [emphasis added.] if name found not designate namespace or class, enumeration, or dependent type, program ill-formed.

so clang conforming, gcc , msvc not.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -