Ping. previous post: http://gcc.gnu.org/ml/gcc-patches/2014-04/msg01938.html
Again bootstrapped/regtested/diffed against xg++ (GCC) 4.10.0 20140508 (experimental) [master revision ed50168:49aa3a5:e79f58c7b12f37014efb7425399c93814cddb4c4] On 29.04.2014 12:58, Momchil Velikov wrote: > 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 3d400bb..cd86f95 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2014-05-08 Momchil Velikov <momchil.veli...@gmail.com> + + PR c++/60994 + * parser.c (cp_parser_class_name): Allow enumeral type as a + nested-name-specifier + 2014-05-08 Paolo Carlini <paolo.carl...@oracle.com> PR c++/13981 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 5542dcd..e7ff57f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19220,7 +19220,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 aa92e3b..60cbe3d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-05-08 Momchil Velikov <momchil.veli...@gmail.com> + + PR c++/60994 + * g++.dg/cpp0x/scoped_enum3.C: New testcase. + 2014-05-08 Joseph Myers <jos...@codesourcery.com> * gcc.target/i386/avx256-unaligned-load-2.c, 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" } +}