GCC should not instantiate the definition of the scoped enumeration: template<typename T> struct A { enum class B { X = T::value }; }; int main() { A<int> a; } GCC error: main1.cpp: In instantiation of ‘A<int>’: main1.cpp:9:10: instantiated from here main1.cpp:3:14: error: ‘value’ is not a member of ‘int’ This code looks well-formed. Only if we look into the enumeration, as "A<int>::B::X", the definition of the enumeration is required to exist and thus implicitly instantiated. This is specified at 14.7.1p1 and p2.
(In reply to Johannes Schaub from comment #0) > GCC should not instantiate the definition of the scoped enumeration: > > template<typename T> > struct A { > enum class B { > X = T::value > }; > }; > > int main() { > A<int> a; > } > > GCC error: > > main1.cpp: In instantiation of ‘A<int>’: > main1.cpp:9:10: instantiated from here > main1.cpp:3:14: error: ‘value’ is not a member of ‘int’ > > This code looks well-formed. Only if we look into the enumeration, as > "A<int>::B::X", the definition of the enumeration is required to exist and > thus implicitly instantiated. This is specified at 14.7.1p1 and p2. Confirmed that g++ rejects it, but clang rejects it too: $ /usr/local/bin/g++ -c -Wall -Wextra -pedantic 49224.cc 49224.cc: In instantiation of ‘struct A<int>’: 49224.cc:9:9: required from here 49224.cc:3:13: error: ‘value’ is not a member of ‘int’ enum class B { ^ 49224.cc: In function ‘int main()’: 49224.cc:9:9: warning: unused variable ‘a’ [-Wunused-variable] A<int> a; ^ $ /sw/opt/llvm-3.1/bin/clang++ -c -Wall -Wextra -pedantic 49224.cc 49224.cc:3:7: error: expected identifier or '{' enum class B { ^ 49224.cc:3:2: warning: declaration does not declare anything [-Wmissing-declarations] enum class B { ^~~~ 49224.cc:9:9: warning: unused variable 'a' [-Wunused-variable] A<int> a; ^ 2 warnings and 1 error generated. $ Since I'm not sure if this is intentional or not, I'm leaving it UNCONFIRMED.
Actually scratch that, my version of clang is old so it doesn't default to c++11. When I manually force -std=c++0x, clang accepts the code, while g++ still rejects it: $ /usr/local/bin/g++ -c -Wall -Wextra -pedantic -std=c++0x 49224.cc 49224.cc: In instantiation of ‘struct A<int>’: 49224.cc:9:9: required from here 49224.cc:3:13: error: ‘value’ is not a member of ‘int’ enum class B { ^ 49224.cc: In function ‘int main()’: 49224.cc:9:9: warning: unused variable ‘a’ [-Wunused-variable] A<int> a; ^ $ /sw/opt/llvm-3.1/bin/clang++ -c -Wall -Wextra -pedantic -std=c++0x 49224.cc 49224.cc:9:9: warning: unused variable 'a' [-Wunused-variable] A<int> a; ^ 1 warning generated. $ So confirming then.
cc-ing c++ FE maintainers
*** Bug 86183 has been marked as a duplicate of this bug. ***