C: fix-it hint for removing stray semicolons
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 25 Apr 2017 14:03:55 +0000 (14:03 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Tue, 25 Apr 2017 14:03:55 +0000 (14:03 +0000)
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

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/semicolon-fixits.c [new file with mode: 0644]

index 143aff925236a2b95e9021127fc504d7d711851e..5587e2f8b84ac0b786de36cc8308b603566035ed 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-25  David Malcolm  <dmalcolm@redhat.com>
+
+       * c-parser.c (c_parser_struct_or_union_specifier): Add fix-it
+       hint for removing extra semicolon.
+
 2017-04-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/80468
index 988369e41938ed65171ff1f97492f87929484a6a..9398652a90aeaa590783e5eb8241317fa90ae2cf 100644 (file)
@@ -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;
            }
index a8e24e979ff278a5dab9438997197b7d917302b7..b369bb5b8397c7c0d57b3e90cadad07998fa3035 100644 (file)
@@ -1,3 +1,7 @@
+2017-04-25  David Malcolm  <dmalcolm@redhat.com>
+
+       * gcc.dg/semicolon-fixits.c: New test case.
+
 2017-04-25  David Malcolm  <dmalcolm@redhat.com>
 
        * 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 (file)
index 0000000..e7d5322
--- /dev/null
@@ -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 "" } */