Commit dbc4ecfc by Volker Reichelt Committed by Volker Reichelt

parser.c (cp_parser_decl_specifier_seq): Add fix-it hints for friend outside…

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
parent a64559a5
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> 2017-07-17 Nathan Sidwell <nathan@acm.org>
* class.c (maybe_warn_about_overly_private_class): Ignore public * class.c (maybe_warn_about_overly_private_class): Ignore public
......
...@@ -13382,7 +13382,9 @@ cp_parser_decl_specifier_seq (cp_parser* parser, ...@@ -13382,7 +13382,9 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
case RID_FRIEND: case RID_FRIEND:
if (!at_class_scope_p ()) 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); cp_lexer_purge_token (parser->lexer);
} }
else else
...@@ -13444,10 +13446,13 @@ cp_parser_decl_specifier_seq (cp_parser* parser, ...@@ -13444,10 +13446,13 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
/* Consume the token. */ /* Consume the token. */
cp_lexer_consume_token (parser->lexer); cp_lexer_consume_token (parser->lexer);
/* Complain about `auto' as a storage specifier, if /* Complain about `auto' as a storage specifier, if
we're complaining about C++0x compatibility. */ we're complaining about C++0x compatibility. */
warning_at (token->location, OPT_Wc__11_compat, "%<auto%>" gcc_rich_location richloc (token->location);
" changes meaning in C++11; please remove it"); 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. */ /* Set the storage class anyway. */
cp_parser_set_storage_class (parser, decl_specs, RID_AUTO, cp_parser_set_storage_class (parser, decl_specs, RID_AUTO,
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> 2017-07-17 Nathan Sidwell <nathan@acm.org>
* g++.dg/warn/ctor-dtor-privacy-3.C: New. * g++.dg/warn/ctor-dtor-privacy-3.C: New.
......
// { dg-do compile { target c++11 } } // { 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 // Test warning for use of auto in C++98 mode with C++11
// compatibility warnings // compatibility warnings
void f() 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 "" } */
} }
// { 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 "" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment