Patchwork Better error reporting for missing semicolons after a struct definition

login
register
mail settings
Submitter Joseph S. Myers
Date Nov. 10, 2010, 2:05 a.m.
Message ID <Pine.LNX.4.64.1011100204580.6963@digraph.polyomino.org.uk>
Download mbox | patch
Permalink /patch/70606/
State New
Headers show

Comments

Joseph S. Myers - Nov. 10, 2010, 2:05 a.m.
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.
Paolo Bonzini - Nov. 10, 2010, 8:59 a.m.
On 11/10/2010 03:05 AM, Joseph S. Myers wrote:
> Perhaps you could post an updated version of your patch to improve
> diagnostics for missing semicolons, relative to current trunk?

Yes, I'll commit the c++-compat patch first so that there will be no 
prerequisite.

Paolo

Patch

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)