Patchwork [C++] PR 51226

login
register
mail settings
Submitter Paolo Carlini
Date May 7, 2013, 7:37 p.m.
Message ID <51895803.7060003@oracle.com>
Download mbox | patch
Permalink /patch/242437/
State New
Headers show

Comments

Paolo Carlini - May 7, 2013, 7:37 p.m.
Hi,

On 05/07/2013 06:49 PM, Jason Merrill wrote:
> On 05/07/2013 06:24 AM, Paolo Carlini wrote:
>> I'm not sure if it would be more correct to explicitly
>> cp_parser_abort_tentative_parse before returning
> Well, there needs to be something to match the 
> cp_parser_parse_tentatively before this function returns.  But in this 
> case the code is indeed an enum-specifier, so I think it would be 
> better to parse it as one rather than return early.
I understand. What about the below? Additionally to the error message 
about the number of template arguments we emit a:

51226.C:6:31: error: expected unqualified-id at end of input
  template<> enum A<>::E : int {}

which probably is expected in such cases (fwiw, clang also emits it)

Thanks,
Paolo.

///////////////////
Jason Merrill - May 8, 2013, 2:33 p.m.
OK.

Jason

Patch

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 198676)
+++ cp/parser.c	(working copy)
@@ -14856,6 +14856,8 @@  cp_parser_enum_specifier (cp_parser* parser)
 	      type = NULL_TREE;
 	    }
 	}
+      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);
@@ -14965,7 +14967,8 @@  cp_parser_enum_specifier (cp_parser* parser)
   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
     {
       timevar_push (TV_PARSE_ENUM);
-      if (nested_name_specifier)
+      if (nested_name_specifier
+	  && nested_name_specifier != error_mark_node)
 	{
 	  /* The following catches invalid code such as:
 	     enum class S<int>::E { A, B, C }; */
Index: testsuite/g++.dg/cpp0x/pr51226.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr51226.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/pr51226.C	(working copy)
@@ -0,0 +1,9 @@ 
+// PR c++/51226
+// { dg-do compile { target c++11 } }
+
+template<int> struct A           // { dg-error "provided" }
+{
+  enum E : int;
+};
+
+template<> enum A<>::E : int {}  // { dg-error "wrong number|expected" }