Hello, gcc version 4.10.0 20140428 (experimental) (GCC)
Compiling (with c++ -c -std=c++11 b.cc) the following program enum struct A { n = 3 }; int foo() { int A; return A::n; } results in the error: b.cc: In function 'int foo()': b.cc:10:10: error: 'A' is not a class, namespace, or enumeration return A::n; ^ According to the C++11 Standard, [basic.lookup.qual] #1 "If a :: scope resolution operator in a nested-name-specifier is not preceded by a decltype-specifier, lookup of the name preceding that :: considers only namespaces, types, and templates whose specializations are types." GCC ought not to resolve "A" to the local variable, but to the enumeration type. This is very similar to the example in the standard struct A { static int n; }; int foo() { int A; return A::n; } which is compiled correctly by GCC, though. Please, review this proposed fix. Bootstrapped/regtested for C/C++ on x86_64-unknown-linux-gnu. ~chill
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a5f3829..36c07a6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2014-04-29 Momchil Velikov <momchil.veli...@gmail.com> + + PR c++/60994 + * parser.c (cp_parser_class_name): Allow enumeral type as a + nested-name-specifier + 2014-04-28 Paolo Carlini <paolo.carl...@oracle.com> PR c++/59120 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 962cace..460535e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19218,7 +19218,8 @@ cp_parser_class_name (cp_parser *parser, } else if (TREE_CODE (decl) != TYPE_DECL || TREE_TYPE (decl) == error_mark_node - || !MAYBE_CLASS_TYPE_P (TREE_TYPE (decl)) + || !(MAYBE_CLASS_TYPE_P (TREE_TYPE (decl)) + || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE) /* In Objective-C 2.0, a classname followed by '.' starts a dot-syntax expression, and it's not a type-name. */ || (c_dialect_objc () diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b2f07c6..0d9468e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-04-29 Momchil Velikov <momchil.veli...@gmail.com> + + PR c++/60994 + * g++.dg/cpp0x/scoped_enum3.C: New testcase. + 2014-04-28 Martin Jambor <mjam...@suse.cz> * gcc.dg/tree-ssa/sra-14.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/scoped_enum3.C b/gcc/testsuite/g++.dg/cpp0x/scoped_enum3.C new file mode 100644 index 0000000..ba527cb --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/scoped_enum3.C @@ -0,0 +1,12 @@ +// { dg-do compile { target c++11 } } +enum struct A +{ + n = 3 +}; + +int +foo() +{ + int A; + return A::n; // { dg-error "cannot convert 'A' to 'int' in return" } +}