C++: fix-it hint for removing stray semicolons
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 25 Apr 2017 14:10:52 +0000 (14:10 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Tue, 25 Apr 2017 14:10:52 +0000 (14:10 +0000)
gcc/cp/ChangeLog:
* parser.c (cp_parser_member_declaration): Add fix-it hint
for removing stray semicolons.

gcc/testsuite/ChangeLog:
* g++.dg/semicolon-fixits.C: New test case.

From-SVN: r247244

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

index ff80b33539d73caab40d71335df3c9d49921a53b..9c8ad1077e452b763e10d3c1eeeb6af2b5a8fa07 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-25  David Malcolm  <dmalcolm@redhat.com>
+
+       * parser.c (cp_parser_member_declaration): Add fix-it hint
+       for removing stray semicolons.
+
 2017-04-25  David Malcolm  <dmalcolm@redhat.com>
 
        * name-lookup.c (get_std_name_hint): New function.
index 31eb3d2e155f0d08b461855b86780c3007b99745..c9780f801db5a43fdd5410d785401ef164fb5a8e 100644 (file)
@@ -23127,7 +23127,11 @@ cp_parser_member_declaration (cp_parser* parser)
        {
          cp_token *token = cp_lexer_peek_token (parser->lexer);
          if (!in_system_header_at (token->location))
-           pedwarn (token->location, OPT_Wpedantic, "extra %<;%>");
+           {
+             gcc_rich_location richloc (token->location);
+             richloc.add_fixit_remove ();
+             pedwarn_at_rich_loc (&richloc, OPT_Wpedantic, "extra %<;%>");
+           }
        }
       else
        {
index b369bb5b8397c7c0d57b3e90cadad07998fa3035..2c00ce853985518026f3e4e42d89895683a8a62a 100644 (file)
@@ -1,3 +1,7 @@
+2017-04-25  David Malcolm  <dmalcolm@redhat.com>
+
+       * g++.dg/semicolon-fixits.C: New test case.
+
 2017-04-25  David Malcolm  <dmalcolm@redhat.com>
 
        * gcc.dg/semicolon-fixits.c: New test case.
diff --git a/gcc/testsuite/g++.dg/semicolon-fixits.C b/gcc/testsuite/g++.dg/semicolon-fixits.C
new file mode 100644 (file)
index 0000000..a9cc783
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-options "-fdiagnostics-show-caret -Wpedantic" } */
+
+/* Struct with extra semicolon.  */
+struct s1 { int i;; }; /* { dg-warning "19: extra .;." } */
+/* { dg-begin-multiline-output "" }
+ struct s1 { int i;; };
+                   ^
+                   -
+   { dg-end-multiline-output "" } */
+
+/* Union with extra semicolon.  */
+union u1 { int i;; }; /* { dg-warning "18: extra .;." } */
+/* { dg-begin-multiline-output "" }
+ union u1 { int i;; };
+                  ^
+                  -
+   { dg-end-multiline-output "" } */