This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C: detect more missing semicolons (PR c/7356)
- From: Jeff Law <law at redhat dot com>
- To: David Malcolm <dmalcolm at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Date: Wed, 25 Oct 2017 09:59:35 -0600
- Subject: Re: [PATCH] C: detect more missing semicolons (PR c/7356)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=law at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 72D22806BA
- References: <1507750371-60739-1-git-send-email-dmalcolm@redhat.com>
On 10/11/2017 01:32 PM, David Malcolm wrote:
> [This patch assumes the two patches here:
> https://gcc.gnu.org/ml/gcc-patches/2017-10/msg00274.html ]
I see the patch directly referenced in that message on the trunk. But
I'm not sure what you mean by "two patches". If there's a prereq that
hasn't been approved, let me know.
>
> c_parser_declaration_or_fndef has logic for parsing what might be
> either a declaration or a function definition.
>
> This patch adds a test to detect cases where a semicolon would have
> terminated the decls as a declaration, where the token that follows
> would start a new declaration specifier, and updates the error message
> accordingly, with a fix-it hint.
>
> This addresses PR c/7356, fixing the case of a stray token before a
> #include which previously gave inscrutable output, and improving e.g.:
>
> int i
> int j;
>
> from:
>
> t.c:2:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
> int j;
> ^~~
>
> to:
>
> t.c:1:6: error: expected ';' before 'int'
> int i
> ^
> ;
> int j;
> ~~~
>
> The patch also adds a test for PR c/44515 as a baseline.
Personally I find the current error easier to digest. It quite clearly
tells me to look before the current token and shove in an appropriate
thingie :-) The extra vertical space, to me, makes the error message
harder to parse.
But I can see how others would prefer to see the point where the
punctuation was missing. So I won't let my biases get in the way here.
>
> gcc/c/ChangeLog:
> PR c/7356
> * c-parser.c (c_parser_declaration_or_fndef): Detect missing
> semicolons.
>
> gcc/testsuite/ChangeLog:
> PR c/7356
> PR c/44515
> * c-c++-common/pr44515.c: New test case.
> * gcc.dg/pr7356-2.c: New test case.
> * gcc.dg/pr7356.c: New test case.
> * gcc.dg/spellcheck-typenames.c: Update the "singed" char "TODO"
> case to reflect changes to output.
> * gcc.dg/noncompile/920923-1.c: Add dg-warning to reflect changes
> to output.
OK.
jeff