Patchwork [C++] PR 40821

login
register
mail settings
Submitter Paolo Carlini
Date May 21, 2012, 1:47 p.m.
Message ID <4FBA477E.5050609@oracle.com>
Download mbox | patch
Permalink /patch/160362/
State New
Headers show

Comments

Paolo Carlini - May 21, 2012, 1:47 p.m.
Hi,

this is a rather old diagnostic issue, already reported at least 3 
times, recently too.

I tried various small variants of the same idea, and the below appears 
to work well enough: it tells the user about all the missing open and 
closed parentheses and overall the diagnostic is quite similar in terms 
of quality and quantity to what EDG produces, for example.

Booted and tested x86_64-linux.

Thanks,
Paolo.

////////////////////////
/cp
2012-05-21  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/40821
	* parser.c (cp_parser_attributes_opt): Enforce error checking of
	unbalanced parentheses in the presence of tentative parsing.

/testsuite
2012-05-21  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/40821
	* g++.dg/ext/attrib46.C: New.
Jason Merrill - May 21, 2012, 2:53 p.m.
OK.

Jason

Patch

Index: testsuite/g++.dg/ext/attrib46.C
===================================================================
--- testsuite/g++.dg/ext/attrib46.C	(revision 0)
+++ testsuite/g++.dg/ext/attrib46.C	(revision 0)
@@ -0,0 +1,4 @@ 
+// PR c++/40821
+
+struct __attribute__((aligned(8)) S1 { int i; }; // { dg-error "expected" }
+struct __attribute__( aligned(8)  S2 { int i; }; // { dg-error "expected" }
Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 187704)
+++ cp/parser.c	(working copy)
@@ -20052,6 +20052,7 @@  cp_parser_attributes_opt (cp_parser* parser)
     {
       cp_token *token;
       tree attribute_list;
+      bool ok = true;
 
       /* Peek at the next token.  */
       token = cp_lexer_peek_token (parser->lexer);
@@ -20076,8 +20077,12 @@  cp_parser_attributes_opt (cp_parser* parser)
 	attribute_list = NULL;
 
       /* Look for the two `)' tokens.  */
-      cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
-      cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+      if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+	ok = false;
+      if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+	ok = false;
+      if (!ok)
+	cp_parser_skip_to_end_of_statement (parser);
 
       /* Add these new attributes to the list.  */
       attributes = chainon (attributes, attribute_list);