This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Better error reporting for missing semicolons after a struct definition


On Tue, 9 Nov 2010, Paolo Bonzini wrote:

> On 11/05/2010 07:04 PM, Joseph S. Myers wrote:
> > Consider the following testcase.
> > 
> > struct s { struct { int a; } };
> > int *f(struct s *p) { return &p->a; }
> 
> The attached patch (mostly untested) fixes this testcase.  This will also
> pedwarn:

That patch seems much more complicated than I expected and I don't see
why most of the changes in it should be needed.  I've applied this
patch (bootstrapped with no regressions on x86_64-unknown-linux-gnu)
to fix the testcase I gave in what seems to me to be the natural way.

Perhaps you could post an updated version of your patch to improve
diagnostics for missing semicolons, relative to current trunk?

2010-11-09  Joseph Myers  <joseph@codesourcery.com>

	* c-parser.c (c_parser_struct_declaration): Handle declaration
	specifiers followed by CPP_CLOSE_BRACE.

testsuite:
2010-11-09  Joseph Myers  <joseph@codesourcery.com>

	* gcc.dg/struct-semi-4.c: New test.

Index: gcc/testsuite/gcc.dg/struct-semi-4.c
===================================================================
--- gcc/testsuite/gcc.dg/struct-semi-4.c	(revision 0)
+++ gcc/testsuite/gcc.dg/struct-semi-4.c	(revision 0)
@@ -0,0 +1,7 @@
+/* Test for missing semicolons in structures: anonymous structures and
+   similar cases.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct s { struct { int a; } }; /* { dg-warning "no semicolon" } */
+int *f (struct s *p) { return &p->a; }
Index: gcc/c-parser.c
===================================================================
--- gcc/c-parser.c	(revision 166433)
+++ gcc/c-parser.c	(working copy)
@@ -2395,7 +2395,8 @@ c_parser_struct_declaration (c_parser *p
       return NULL_TREE;
     }
   finish_declspecs (specs);
-  if (c_parser_next_token_is (parser, CPP_SEMICOLON))
+  if (c_parser_next_token_is (parser, CPP_SEMICOLON)
+      || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
     {
       tree ret;
       if (!specs->type_seen_p)

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]