diff options
author | Volker Reichelt <v.reichelt@netcologne.de> | 2017-07-17 16:58:00 +0000 |
---|---|---|
committer | Volker Reichelt <reichelt@gcc.gnu.org> | 2017-07-17 16:58:00 +0000 |
commit | dbc4ecfc5772cc21b2a1f95ec97d186d7b350f8f (patch) | |
tree | ce133a70b7b0ed1ef50c49e0ff1fb510b8eb8b3e /gcc | |
parent | a64559a5fc0373710a6f3ae7a8b569b439146fde (diff) | |
download | gcc-dbc4ecfc5772cc21b2a1f95ec97d186d7b350f8f.zip gcc-dbc4ecfc5772cc21b2a1f95ec97d186d7b350f8f.tar.gz gcc-dbc4ecfc5772cc21b2a1f95ec97d186d7b350f8f.tar.bz2 |
parser.c (cp_parser_decl_specifier_seq): Add fix-it hints for friend outside class and obsolete auto as...
* parser.c (cp_parser_decl_specifier_seq): Add fix-it hints for
friend outside class and obsolete auto as storage-class-specifier.
* g++.dg/diagnostic/friend1.C: New test.
* g++.dg/cpp0x/auto1.C: Add check for fix-it hint.
From-SVN: r250282
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/parser.c | 15 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/auto1.C | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/diagnostic/friend1.C | 8 |
5 files changed, 35 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fef4c21..e46c128 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2017-07-17 Volker Reichelt <v.reichelt@netcologne.de> + + * parser.c (cp_parser_decl_specifier_seq): Add fix-it hints for + friend outside class and obsolete auto as storage-class-specifier. + 2017-07-17 Nathan Sidwell <nathan@acm.org> * class.c (maybe_warn_about_overly_private_class): Ignore public diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d767797..88d0b2b2 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -13382,7 +13382,9 @@ cp_parser_decl_specifier_seq (cp_parser* parser, case RID_FRIEND: if (!at_class_scope_p ()) { - error_at (token->location, "%<friend%> used outside of class"); + gcc_rich_location richloc (token->location); + richloc.add_fixit_remove (); + error_at_rich_loc (&richloc, "%<friend%> used outside of class"); cp_lexer_purge_token (parser->lexer); } else @@ -13444,10 +13446,13 @@ cp_parser_decl_specifier_seq (cp_parser* parser, /* Consume the token. */ cp_lexer_consume_token (parser->lexer); - /* Complain about `auto' as a storage specifier, if - we're complaining about C++0x compatibility. */ - warning_at (token->location, OPT_Wc__11_compat, "%<auto%>" - " changes meaning in C++11; please remove it"); + /* Complain about `auto' as a storage specifier, if + we're complaining about C++0x compatibility. */ + gcc_rich_location richloc (token->location); + richloc.add_fixit_remove (); + warning_at_rich_loc (&richloc, OPT_Wc__11_compat, + "%<auto%> changes meaning in C++11; " + "please remove it"); /* Set the storage class anyway. */ cp_parser_set_storage_class (parser, decl_specs, RID_AUTO, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a0ca514..ebd6eaf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-07-17 Volker Reichelt <v.reichelt@netcologne.de> + + * g++.dg/diagnostic/friend1.C: New test. + * g++.dg/cpp0x/auto1.C: Add check for fix-it hint. + 2017-07-17 Nathan Sidwell <nathan@acm.org> * g++.dg/warn/ctor-dtor-privacy-3.C: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/auto1.C b/gcc/testsuite/g++.dg/cpp0x/auto1.C index b8d3905..dd8f5fc 100644 --- a/gcc/testsuite/g++.dg/cpp0x/auto1.C +++ b/gcc/testsuite/g++.dg/cpp0x/auto1.C @@ -1,9 +1,14 @@ // { dg-do compile { target c++11 } } -// { dg-options "-std=c++98 -Wc++11-compat" } +// { dg-options "-std=c++98 -Wc++11-compat -fdiagnostics-show-caret" } // Test warning for use of auto in C++98 mode with C++11 // compatibility warnings void f() { - auto int x = 5; // { dg-warning "changes meaning" } + auto int x = 5; /* { dg-warning "changes meaning" } + { dg-begin-multiline-output "" } + auto int x = 5; + ^~~~ + ---- + { dg-end-multiline-output "" } */ } diff --git a/gcc/testsuite/g++.dg/diagnostic/friend1.C b/gcc/testsuite/g++.dg/diagnostic/friend1.C new file mode 100644 index 0000000..a35f92a --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/friend1.C @@ -0,0 +1,8 @@ +// { dg-options "-fdiagnostics-show-caret" } + +friend void foo(); /* { dg-error "used outside of class" } + { dg-begin-multiline-output "" } + friend void foo(); + ^~~~~~ + ------ + { dg-end-multiline-output "" } */ |