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 ff80b33..9c8ad10 100644 (file)
@@ -1,5 +1,10 @@
 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.
        (maybe_suggest_missing_header): New function.
        (suggest_alternative_in_explicit_scope): Call
index 31eb3d2..c9780f8 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 b369bb5..2c00ce8 100644 (file)
@@ -1,5 +1,9 @@
 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.
 
 2017-04-25  David Malcolm  <dmalcolm@redhat.com>
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 "" } */