From: David Malcolm Date: Tue, 25 Apr 2017 14:03:55 +0000 (+0000) Subject: C: fix-it hint for removing stray semicolons X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1c4ea66f24bc3801448d5c88847fc97d4e2767ee;p=gcc.git C: fix-it hint for removing stray semicolons gcc/c/ChangeLog: * c-parser.c (c_parser_struct_or_union_specifier): Add fix-it hint for removing extra semicolon. gcc/testsuite/ChangeLog: * gcc.dg/semicolon-fixits.c: New test case. From-SVN: r247243 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 143aff92523..5587e2f8b84 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2017-04-25 David Malcolm + + * c-parser.c (c_parser_struct_or_union_specifier): Add fix-it + hint for removing extra semicolon. + 2017-04-21 Jakub Jelinek PR c/80468 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 988369e4193..9398652a90a 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -2948,8 +2948,13 @@ c_parser_struct_or_union_specifier (c_parser *parser) /* Parse any stray semicolon. */ if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { - pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, - "extra semicolon in struct or union specified"); + location_t semicolon_loc + = c_parser_peek_token (parser)->location; + gcc_rich_location richloc (semicolon_loc); + richloc.add_fixit_remove (); + pedwarn_at_rich_loc + (&richloc, OPT_Wpedantic, + "extra semicolon in struct or union specified"); c_parser_consume_token (parser); continue; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a8e24e979ff..b369bb5b839 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-04-25 David Malcolm + + * gcc.dg/semicolon-fixits.c: New test case. + 2017-04-25 David Malcolm * g++.dg/lookup/missing-std-include.C: New test file. diff --git a/gcc/testsuite/gcc.dg/semicolon-fixits.c b/gcc/testsuite/gcc.dg/semicolon-fixits.c new file mode 100644 index 00000000000..e7d532296d2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/semicolon-fixits.c @@ -0,0 +1,17 @@ +/* { dg-options "-fdiagnostics-show-caret -Wpedantic" } */ + +/* Struct with extra semicolon. */ +struct s1 { int i;; }; /* { dg-warning "19: extra semicolon in struct or union specified" } */ +/* { dg-begin-multiline-output "" } + struct s1 { int i;; }; + ^ + - + { dg-end-multiline-output "" } */ + +/* Union with extra semicolon. */ +union u1 { int i;; }; /* { dg-warning "18: extra semicolon in struct or union specified" } */ +/* { dg-begin-multiline-output "" } + union u1 { int i;; }; + ^ + - + { dg-end-multiline-output "" } */