diff mbox

[C++] PR 67318 ("[6 regression] Parsing error when using abbreviated integral type names in template parameter pack declaration")

Message ID 55F060D3.4070208@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Sept. 9, 2015, 4:39 p.m. UTC
Hi,

I tracked down this regression to r225621, a clean up committed by Jason 
a while ago: unless we want to try something more aggressive, we can fix 
it the regression by simply restoring a few lines in 
cp_parser_template_parameter which consume the ellipsis. To clarify 
implementation-wise, the types affected are essentially all those for 
which cp_parser_simple_type_specifier (thus 
cp_parser_parameter_declaration) doesn't set the type in decl_specs:

       if (decl_specs
       && (token->keyword != RID_SIGNED
           && token->keyword != RID_UNSIGNED
           && token->keyword != RID_SHORT
           && token->keyword != RID_LONG))
     cp_parser_set_decl_spec_type (decl_specs,
                       type,
                       token,
                       /*type_definition_p=*/false);

Weird that we didn't have any testcase!

Tested x86_64-linux.

Thanks,
Paolo.

/////////////////////////
/cp
2015-09-09  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/67318
	* parser.c (cp_parser_template_parameter): Revert a few lines of
	r225621: consume the ellipsis and set *is_parameter_pack to true.

/testsuite
2015-09-09  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/67318
	* g++.dg/cpp0x/variadic166.C: New.

Comments

Jason Merrill Sept. 9, 2015, 6:42 p.m. UTC | #1
We should fix the logic in cp_parser_parameter_declaration to handle 
this, not work around it here.

Jason
Paolo Carlini Sept. 9, 2015, 7:06 p.m. UTC | #2
Hi,

On 09/09/2015 08:42 PM, Jason Merrill wrote:
> We should fix the logic in cp_parser_parameter_declaration to handle 
> this, not work around it here.
Ok, that's what I meant for "more aggressive" ;) I didn't try do that 
immediately when I noticed that the function is called from a few other 
places, but I'll do that now. If I can't sort it out as quickly as I 
want I'll tell you, the issue seems rather annoying...

Thanks!
Paolo.
diff mbox

Patch

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 227586)
+++ cp/parser.c	(working copy)
@@ -13811,6 +13811,20 @@  cp_parser_template_parameter (cp_parser* parser, b
 	/* 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).  */
+  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);
+      maybe_warn_variadic_templates ();
+      
+      *is_parameter_pack = true;
+    }
 
   // The parameter may have been constrained.
   if (is_constrained_parameter (parameter_declarator))
Index: testsuite/g++.dg/cpp0x/variadic166.C
===================================================================
--- testsuite/g++.dg/cpp0x/variadic166.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/variadic166.C	(working copy)
@@ -0,0 +1,14 @@ 
+// PR c++/67318
+// { dg-do compile { target c++11 } }
+
+template<signed...>
+struct MyStruct1;
+
+template<unsigned...>
+struct MyStruct2;
+
+template<short...>
+struct MyStruct3;
+
+template<long...>
+struct MyStruct4;