This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Better error reporting for missing semicolons after a struct definition
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Paolo Bonzini <bonzini at gnu dot org>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 10 Nov 2010 02:05:43 +0000 (UTC)
- Subject: Re: [PATCH] Better error reporting for missing semicolons after a struct definition
- References: <1288367432-3422-2-git-send-email-bonzini@gnu.org> <Pine.LNX.4.64.1011051757580.6382@digraph.polyomino.org.uk> <4CD97A23.90209@gnu.org>
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