diff mbox

[C++] Fix parser ICE with [[...]] and [[unused,...]] (PR c++/77637)

Message ID 20160919215008.GP7282@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Sept. 19, 2016, 9:50 p.m. UTC
Hi!

As the testcase shows, while the grammar has
attribute-list:
  attribute[opt]
  attribute-list , attribute[opt]
  attribute ...
  attribute-list , attribute ...
we are actually parsing it as if the last 2 lines were
  attribute[opt] ...
  attribute-list , attribute[opt] ...
and ICEing when there is no attribute.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk/6.3?

2016-09-19  Jakub Jelinek  <jakub@redhat.com>

	PR c++/77637
	* parser.c (cp_parser_std_attribute_list): Reject ... without
	preceding attribute.

	* g++.dg/cpp0x/gen-attrs-62.C: New test.


	Jakub

Comments

Jason Merrill Sept. 20, 2016, 3:03 p.m. UTC | #1
OK.

On Mon, Sep 19, 2016 at 5:50 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> As the testcase shows, while the grammar has
> attribute-list:
>   attribute[opt]
>   attribute-list , attribute[opt]
>   attribute ...
>   attribute-list , attribute ...
> we are actually parsing it as if the last 2 lines were
>   attribute[opt] ...
>   attribute-list , attribute[opt] ...
> and ICEing when there is no attribute.
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk/6.3?
>
> 2016-09-19  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/77637
>         * parser.c (cp_parser_std_attribute_list): Reject ... without
>         preceding attribute.
>
>         * g++.dg/cpp0x/gen-attrs-62.C: New test.
>
> --- gcc/cp/parser.c.jj  2016-09-16 22:19:39.000000000 +0200
> +++ gcc/cp/parser.c     2016-09-19 10:33:51.481904739 +0200
> @@ -24220,8 +24220,12 @@ cp_parser_std_attribute_list (cp_parser
>        if (token->type == CPP_ELLIPSIS)
>         {
>           cp_lexer_consume_token (parser->lexer);
> -         TREE_VALUE (attribute)
> -           = make_pack_expansion (TREE_VALUE (attribute));
> +         if (attribute == NULL_TREE)
> +           error_at (token->location,
> +                     "expected attribute before %<...%>");
> +         else
> +           TREE_VALUE (attribute)
> +             = make_pack_expansion (TREE_VALUE (attribute));
>           token = cp_lexer_peek_token (parser->lexer);
>         }
>        if (token->type != CPP_COMMA)
> --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-62.C.jj        2016-09-19 10:37:59.414772726 +0200
> +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-62.C   2016-09-19 10:37:28.000000000 +0200
> @@ -0,0 +1,5 @@
> +// PR c++/77637
> +// { dg-do compile { target c++11 } }
> +
> +int [[...]] a;         // { dg-error "expected attribute before '...'" }
> +int [[,,...]] b;       // { dg-error "expected attribute before '...'" }
>
>         Jakub
diff mbox

Patch

--- gcc/cp/parser.c.jj	2016-09-16 22:19:39.000000000 +0200
+++ gcc/cp/parser.c	2016-09-19 10:33:51.481904739 +0200
@@ -24220,8 +24220,12 @@  cp_parser_std_attribute_list (cp_parser
       if (token->type == CPP_ELLIPSIS)
 	{
 	  cp_lexer_consume_token (parser->lexer);
-	  TREE_VALUE (attribute)
-	    = make_pack_expansion (TREE_VALUE (attribute));
+	  if (attribute == NULL_TREE)
+	    error_at (token->location,
+		      "expected attribute before %<...%>");
+	  else
+	    TREE_VALUE (attribute)
+	      = make_pack_expansion (TREE_VALUE (attribute));
 	  token = cp_lexer_peek_token (parser->lexer);
 	}
       if (token->type != CPP_COMMA)
--- gcc/testsuite/g++.dg/cpp0x/gen-attrs-62.C.jj	2016-09-19 10:37:59.414772726 +0200
+++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-62.C	2016-09-19 10:37:28.000000000 +0200
@@ -0,0 +1,5 @@ 
+// PR c++/77637
+// { dg-do compile { target c++11 } }
+
+int [[...]] a;		// { dg-error "expected attribute before '...'" }
+int [[,,...]] b;	// { dg-error "expected attribute before '...'" }