From f523e68a231849653c829aab6b0ccaf99137d0a5 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 21 Oct 2015 22:52:45 +0000 Subject: [PATCH] re PR c++/66781 ("confused by earlier errors, bailing out" with wrong enum within class) /cp 2015-10-21 Paolo Carlini PR c++/66781 * parser.c (cp_parser_enum_specifier): Upon error_at set nested_name_specifier to error_mark_node; improve error message. /testsuite 2015-10-21 Paolo Carlini PR c++/66781 * g++.dg/parse/enum13.C: New. /cp 2015-10-21 Paolo Carlini PR c++/67847 * parser.c (cp_parser_enum_specifier): Reject a nested_name_specifier which doesn't name a class or namespace. /testsuite 2015-10-21 Paolo Carlini PR c++/67847 * g++.dg/parse/enum12.C: New. From-SVN: r229156 --- gcc/cp/ChangeLog | 12 ++++++++++++ gcc/cp/parser.c | 16 ++++++++++++++-- gcc/testsuite/ChangeLog | 10 ++++++++++ gcc/testsuite/g++.dg/parse/enum12.C | 7 +++++++ gcc/testsuite/g++.dg/parse/enum13.C | 8 ++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/parse/enum12.C create mode 100644 gcc/testsuite/g++.dg/parse/enum13.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2a9e873320d..0ed4e29615d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,15 @@ +2015-10-21 Paolo Carlini + + PR c++/66781 + * parser.c (cp_parser_enum_specifier): Upon error_at set + nested_name_specifier to error_mark_node; improve error message. + +2015-10-21 Paolo Carlini + + PR c++/67847 + * parser.c (cp_parser_enum_specifier): Reject a nested_name_specifier + which doesn't name a class or namespace. + 2015-10-21 Ilya Enkovich * call.c (build_conditional_expr_1): Use boolean vector diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index cfe5468a8b5..7555bf3c87a 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -16655,8 +16655,12 @@ cp_parser_enum_specifier (cp_parser* parser) else if (nested_name_specifier == error_mark_node) /* We already issued an error. */; else - error_at (type_start_token->location, - "%qD is not an enumerator-name", identifier); + { + error_at (type_start_token->location, + "%qD does not name an enumeration in %qT", + identifier, nested_name_specifier); + nested_name_specifier = error_mark_node; + } } else { @@ -16783,6 +16787,14 @@ cp_parser_enum_specifier (cp_parser* parser) nested_name_specifier); type = error_mark_node; } + else if (TREE_CODE (nested_name_specifier) != NAMESPACE_DECL + && !CLASS_TYPE_P (nested_name_specifier)) + { + error_at (type_start_token->location, "nested name specifier " + "%qT for enum declaration does not name a class " + "or namespace", nested_name_specifier); + type = error_mark_node; + } /* If that scope does not contain the scope in which the class was originally declared, the program is invalid. */ else if (prev_scope && !is_ancestor (prev_scope, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1c31c22bfeb..ef63b1b0765 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2015-10-21 Paolo Carlini + + PR c++/66781 + * g++.dg/parse/enum13.C: New. + +2015-10-21 Paolo Carlini + + PR c++/67847 + * g++.dg/parse/enum12.C: New. + 2015-10-21 Martin Sebor PR driver/68043 diff --git a/gcc/testsuite/g++.dg/parse/enum12.C b/gcc/testsuite/g++.dg/parse/enum12.C new file mode 100644 index 00000000000..835dacd71a6 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/enum12.C @@ -0,0 +1,7 @@ +// PR c++/67847 + +template < typename T > +class D +{ + enum T::Color {R, G, B} c; // { dg-error "nested name specifier" } +}; diff --git a/gcc/testsuite/g++.dg/parse/enum13.C b/gcc/testsuite/g++.dg/parse/enum13.C new file mode 100644 index 00000000000..102f21953ac --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/enum13.C @@ -0,0 +1,8 @@ +// PR c++/66781 + +class foo +{ +public: + enum foo::bar{}; // { dg-error "does not name an enumeration" } + foo::bar baz; +}; -- 2.30.2