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 1a9ca1942b885ed27867ce867cb316a42ad2aa6e..40d2cc2ac73ff0b169ecf201bf1975cb3eed51c3 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 4714bc6cd8958512dcb00a80fce1d92237dd7c7e..640a601bafad9ef2c39294442be5c56266e92d05 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 696eb272d426656699d329dc6e4c423f40fe6fc8..718de7eae835a83b3b06c8119c9f3c9027a89127 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 "" } */