diff mbox

[C++] PR 34892

Message ID 5088A855.5090504@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 25, 2012, 2:47 a.m. UTC
Hi,

On 10/25/2012 03:53 AM, Jason Merrill wrote:
> We can stop it even sooner:
>
>>   /* If the next token is an ellipsis, and we don't already have it
>>      marked as a parameter pack, then we have a parameter pack (that
>>      has no declarator).  */
>>   if (!*is_parameter_pack
>>       && cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS)
>>       && declarator_can_be_parameter_pack 
>> (parameter_declarator->declarator))
>
> We shouldn't even consider this if there was a default argument.
Ah great, thanks. The below also regtests fine.

Thanks again,
Paolo.

////////////////////////

Comments

Jason Merrill Oct. 25, 2012, 3:21 a.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 192786)
+++ cp/parser.c	(working copy)
@@ -12258,12 +12258,21 @@  cp_parser_template_parameter (cp_parser* parser, b
       parameter_declarator->declarator->parameter_pack_p = false;
     }
 
+  if (parameter_declarator
+      && parameter_declarator->default_argument)
+    {
+      /* Can happen in some cases of erroneous input (c++/34892).  */
+      if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
+	/* Consume the `...' for better error recovery.  */
+	cp_lexer_consume_token (parser->lexer);
+    }
   /* If the next token is an ellipsis, and we don't already have it
      marked as a parameter pack, then we have a parameter pack (that
      has no declarator).  */
-  if (!*is_parameter_pack
-      && cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS)
-      && declarator_can_be_parameter_pack (parameter_declarator->declarator))
+  else if (!*is_parameter_pack
+	   && cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS)
+	   && (declarator_can_be_parameter_pack
+	       (parameter_declarator->declarator)))
     {
       /* Consume the `...'.  */
       cp_lexer_consume_token (parser->lexer);
Index: testsuite/g++.dg/template/crash114.C
===================================================================
--- testsuite/g++.dg/template/crash114.C	(revision 0)
+++ testsuite/g++.dg/template/crash114.C	(working copy)
@@ -0,0 +1,5 @@ 
+// PR c++/34892
+
+template<int=..., int=0> struct A {};  // { dg-error "expected primary" }
+
+A<0> a;