Hi,
I have two fixes for ICEs on invalid code. I'm not completely sure about
the wording of the error message for c++/67847, fwiw, clang issues
something rather similar. The other one should be more straightforward.
Tested x86_64-linux.
Thanks,
Paolo.
/////////////////////
/cp
2015-10-21 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/66781
* parser.c (cp_parser_enum_specifier): Upon error_at set
nested_name_specifier to error_mark_node.
/testsuite
2015-10-21 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/66781
* g++.dg/parse/enum13.C: New.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 229082)
+++ cp/parser.c (working copy)
@@ -16655,8 +16655,11 @@ 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 is not an enumerator-name", identifier);
+ nested_name_specifier = error_mark_node;
+ }
}
else
{
Index: testsuite/g++.dg/parse/enum13.C
===================================================================
--- testsuite/g++.dg/parse/enum13.C (revision 0)
+++ testsuite/g++.dg/parse/enum13.C (working copy)
@@ -0,0 +1,8 @@
+// PR c++/66781
+
+class foo
+{
+public:
+ enum foo::bar{}; // { dg-error "not an enumerator-name" }
+ foo::bar baz;
+};
/cp
2015-10-21 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/67847
* parser.c (cp_parser_enum_specifier): Reject TEMPLATE_TYPE_PARM as
nested_name_specifier.
/testsuite
2015-10-21 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/67847
* g++.dg/parse/enum12.C: New.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 229082)
+++ cp/parser.c (working copy)
@@ -16783,6 +16786,13 @@ cp_parser_enum_specifier (cp_parser* parser)
nested_name_specifier);
type = error_mark_node;
}
+ else if (TREE_CODE (nested_name_specifier) == TEMPLATE_TYPE_PARM)
+ {
+ error_at (type_start_token->location, "nested name specifier "
+ "for enum declaration cannot depend on a template "
+ "parameter, i.e., %qT", 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,
Index: testsuite/g++.dg/parse/enum12.C
===================================================================
--- testsuite/g++.dg/parse/enum12.C (revision 0)
+++ testsuite/g++.dg/parse/enum12.C (working copy)
@@ -0,0 +1,7 @@
+// PR c++/67847
+
+template < typename T >
+class D
+{
+ enum T::Color {R, G, B} c; // { dg-error "template parameter" }
+};