diff mbox series

[C++] Reject invalid GNU attribute syntax (PR c++/87175)

Message ID 20190131225117.GO2135@tucnak
State New
Headers show
Series [C++] Reject invalid GNU attribute syntax (PR c++/87175) | expand

Commit Message

Jakub Jelinek Jan. 31, 2019, 10:51 p.m. UTC
Hi!

THe following patch rejects invalid __attribute__ syntax where one or both
opening parens are missing, but it is accepted anyway.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2019-01-31  Jakub Jelinek  <jakub@redhat.com>

	PR c++/87175
	* parser.c (cp_parser_gnu_attributes_opt): Set ok to false
	if require_open failed.

	* g++.dg/ext/attrib57.C: New test.


	Jakub

Comments

Jason Merrill Feb. 1, 2019, 12:12 a.m. UTC | #1
On 1/31/19 5:51 PM, Jakub Jelinek wrote:
> Hi!
> 
> THe following patch rejects invalid __attribute__ syntax where one or both
> opening parens are missing, but it is accepted anyway.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2019-01-31  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/87175
> 	* parser.c (cp_parser_gnu_attributes_opt): Set ok to false
> 	if require_open failed.

OK.

Jason
diff mbox series

Patch

--- gcc/cp/parser.c.jj	2019-01-28 23:29:40.719949614 +0100
+++ gcc/cp/parser.c	2019-01-31 10:16:22.653631278 +0100
@@ -25768,9 +25768,11 @@  cp_parser_gnu_attributes_opt (cp_parser*
       cp_lexer_consume_token (parser->lexer);
       /* Look for the two `(' tokens.  */
       matching_parens outer_parens;
-      outer_parens.require_open (parser);
+      if (!outer_parens.require_open (parser))
+	ok = false;
       matching_parens inner_parens;
-      inner_parens.require_open (parser);
+      if (!inner_parens.require_open (parser))
+	ok = false;
 
       /* Peek at the next token.  */
       token = cp_lexer_peek_token (parser->lexer);
--- gcc/testsuite/g++.dg/ext/attrib57.C.jj	2019-01-31 10:24:25.353702392 +0100
+++ gcc/testsuite/g++.dg/ext/attrib57.C	2019-01-31 10:23:57.007170898 +0100
@@ -0,0 +1,6 @@ 
+// PR c++/87175
+// { dg-do compile }
+// { dg-options "" }
+
+struct __attribute__)) foo { };	// { dg-error "expected" }
+struct __attribute__()) bar { };// { dg-error "expected" }