parser.c (cp_parser_nested_name_specifier_opt): Add fix-it information to diagnostic...
authorVolker Reichelt <v.reichelt@netcologne.de>
Wed, 26 Apr 2017 16:57:25 +0000 (16:57 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Wed, 26 Apr 2017 16:57:25 +0000 (16:57 +0000)
        * parser.c (cp_parser_nested_name_specifier_opt): Add fix-it
        information to diagnostic of invalid colon in nested-name-specifier.

        * g++.dg/diagnostic/nested-name-1.C: New test.

From-SVN: r247282

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

index 1a9ca19..40d2cc2 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-26  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * parser.c (cp_parser_nested_name_specifier_opt): Add fix-it
+       information to diagnostic of invalid colon in nested-name-specifier.
+
 2017-04-25  Volker Reichelt  <v.reichelt@netcologne.de>
 
        * parser.c (cp_parser_elaborated_type_specifier): Add fix-it to
index 4714bc6..640a601 100644 (file)
@@ -5931,8 +5931,11 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
              && parser->colon_corrects_to_scope_p
              && cp_lexer_peek_nth_token (parser->lexer, 3)->type == CPP_NAME)
            {
-             error_at (token->location,
-                       "found %<:%> in nested-name-specifier, expected %<::%>");
+             gcc_rich_location richloc (token->location);
+             richloc.add_fixit_replace ("::");
+             error_at_rich_loc (&richloc,
+                                "found %<:%> in nested-name-specifier, "
+                                "expected %<::%>");
              token->type = CPP_SCOPE;
            }
 
index 696eb27..718de7e 100644 (file)
@@ -1,3 +1,7 @@
+2017-04-26  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * g++.dg/diagnostic/nested-name-1.C: New test.
+
 2017-04-26  Martin Liska  <mliska@suse.cz>
 
        * gcc.dg/guality/guality.h: Add prefix to test verification.
diff --git a/gcc/testsuite/g++.dg/diagnostic/nested-name-1.C b/gcc/testsuite/g++.dg/diagnostic/nested-name-1.C
new file mode 100644 (file)
index 0000000..a02761c
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-options "-fdiagnostics-show-caret" }
+
+namespace N
+{
+  struct A {};
+}
+
+N:A a;  /* { dg-error "nested-name-specifier" }
+  { dg-begin-multiline-output "" }
+ N:A a;
+  ^
+  ::
+  { dg-end-multiline-output "" } */