parser.c (cp_parser_member_declaration): Add fix-it hints for stray comma and missing...
authorVolker Reichelt <v.reichelt@netcologne.de>
Sat, 29 Apr 2017 22:27:13 +0000 (22:27 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Sat, 29 Apr 2017 22:27:13 +0000 (22:27 +0000)
        * parser.c (cp_parser_member_declaration): Add fix-it hints for
        stray comma and missing semicolon at end of member declaration.

        * g++.dg/diagnostic/member-decl-1.C: New test.

From-SVN: r247412

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/diagnostic/member-decl-1.C [new file with mode: 0644]

index 36e114b794f10820ac38ce85ec802a0188bb8d1a..9c9818fa9ab83967d085e3b2471c0c0dc9b19d8e 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-29  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * parser.c (cp_parser_member_declaration): Add fix-it hints for
+       stray comma and missing semicolon at end of member declaration.
+
 2017-04-27  Volker Reichelt  <v.reichelt@netcologne.de>
 
        * parser.c (cp_parser_cast_expression): Add target type of cast to
index 3917893b06af5f4487cf8d9a33537be3029b2484..95af052454eb9168b628ecb19b7ec4c6b349eead 100644 (file)
@@ -23461,8 +23461,10 @@ cp_parser_member_declaration (cp_parser* parser)
              if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
                {
                  cp_token *token = cp_lexer_previous_token (parser->lexer);
-                 error_at (token->location,
-                           "stray %<,%> at end of member declaration");
+                 gcc_rich_location richloc (token->location);
+                 richloc.add_fixit_remove ();
+                 error_at_rich_loc (&richloc, "stray %<,%> at end of "
+                                    "member declaration");
                }
            }
          /* If the next token isn't a `;', then we have a parse error.  */
@@ -23473,8 +23475,10 @@ cp_parser_member_declaration (cp_parser* parser)
                 actual semicolon is missing.  Find the previous token
                 and use that for our error position.  */
              cp_token *token = cp_lexer_previous_token (parser->lexer);
-             error_at (token->location,
-                       "expected %<;%> at end of member declaration");
+             gcc_rich_location richloc (token->location);
+             richloc.add_fixit_insert_after (";");
+             error_at_rich_loc (&richloc, "expected %<;%> at end of "
+                                "member declaration");
 
              /* Assume that the user meant to provide a semicolon.  If
                 we were to cp_parser_skip_to_end_of_statement, we might
index 2d3d02b018cd138962723f531e4b5f4f62225c7d..818e002b7bf07cc618a1f3f83d997f9f2602546a 100644 (file)
@@ -1,3 +1,7 @@
+2017-04-29  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * g++.dg/diagnostic/member-decl-1.C: New test.
+
 2017-04-29  Marc Glisse  <marc.glisse@inria.fr>
 
        PR tree-optimization/80487
diff --git a/gcc/testsuite/g++.dg/diagnostic/member-decl-1.C b/gcc/testsuite/g++.dg/diagnostic/member-decl-1.C
new file mode 100644 (file)
index 0000000..be1ef85
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-options "-fdiagnostics-show-caret" }
+
+struct A
+{
+  int i,;  /* { dg-error "stray .,. at end of member declaration" }
+  { dg-begin-multiline-output "" }
+   int i,;
+        ^
+        -
+  { dg-end-multiline-output "" } */
+
+  int j  /* { dg-error "expected .;. at end of member declaration" }
+  { dg-begin-multiline-output "" }
+   int j
+       ^
+        ;
+  { dg-end-multiline-output "" } */
+};