diff mbox

[C++,Patches] PR c++/66781 and c++/67847

Message ID 5627A31B.90402@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 21, 2015, 2:37 p.m. UTC
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.carlini@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.carlini@oracle.com>

	PR c++/66781
	* g++.dg/parse/enum13.C: New.

/cp
2015-10-21  Paolo Carlini  <paolo.carlini@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.carlini@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" }
+};

Comments

Jason Merrill Oct. 21, 2015, 7:19 p.m. UTC | #1
On 10/21/2015 04:37 AM, Paolo Carlini wrote:
> +		    "%qD is not an enumerator-name", identifier);

This should be enum-name or "does not name an enumeration".  We should 
also print the nested-name-specifier.

> +	      error_at (type_start_token->location, "nested name specifier "
> +			"for enum declaration cannot depend on a template "
> +			"parameter, i.e., %qT", nested_name_specifier);

It can in, e.g.,

template <class T>
enum A<T>::E { ... };

We could hit this same ICE for anything that is not a class or 
namespace, i.e. any of WILDCARD_TYPE_P.  That's the problem here: the 
nested-name-specifier on a definition needs to name a class or namespace.

Jason
diff mbox

Patch

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;
+};