From a480422d0ad67c0ced6b1a3a21c228277381b053 Mon Sep 17 00:00:00 2001 From: Volker Reichelt Date: Wed, 26 Apr 2017 16:57:25 +0000 Subject: [PATCH] parser.c (cp_parser_nested_name_specifier_opt): Add fix-it information to diagnostic of invalid colon in nested-name-specifier. * 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 | 5 +++++ gcc/cp/parser.c | 7 +++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/diagnostic/nested-name-1.C | 13 +++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/nested-name-1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1a9ca1942b8..40d2cc2ac73 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2017-04-26 Volker Reichelt + + * 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 * parser.c (cp_parser_elaborated_type_specifier): Add fix-it to diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4714bc6cd89..640a601bafa 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 696eb272d42..718de7eae83 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-04-26 Volker Reichelt + + * g++.dg/diagnostic/nested-name-1.C: New test. + 2017-04-26 Martin Liska * 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 index 00000000000..a02761cef7b --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/nested-name-1.C @@ -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 "" } */ -- 2.30.2