[Bug c/7356] syntax errors immediately before an #include are reported for within the included file
dmalcolm at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Oct 25 23:54:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7356
--- Comment #8 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Author: dmalcolm
Date: Wed Oct 25 23:53:41 2017
New Revision: 254093
URL: https://gcc.gnu.org/viewcvs?rev=254093&root=gcc&view=rev
Log:
C: detect more missing semicolons (PR c/7356)
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 that 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;
~~~
gcc.dg/noncompile/920923-1.c needs a slight update, as the output for
the first line changes from:
920923-1.c:2:14: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'unsigned'
typedef BYTE unsigned char; /* { dg-error "expected" } */
^~~~~~~~
to:
920923-1.c:2:13: error: expected ';' before 'unsigned'
typedef BYTE unsigned char; /* { dg-error "expected" } */
^~~~~~~~~
;
920923-1.c:2:1: warning: useless type name in empty declaration
typedef BYTE unsigned char; /* { dg-error "expected" } */
^~~~~~~
The patch also adds a test for PR c/44515 as a baseline.
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.
Added:
trunk/gcc/testsuite/c-c++-common/pr44515.c
trunk/gcc/testsuite/gcc.dg/pr7356-2.c
trunk/gcc/testsuite/gcc.dg/pr7356.c
Modified:
trunk/gcc/c/ChangeLog
trunk/gcc/c/c-parser.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.dg/noncompile/920923-1.c
trunk/gcc/testsuite/gcc.dg/spellcheck-typenames.c
More information about the Gcc-bugs
mailing list