On 04/29/2017 04:23 PM, Volker Reichelt wrote:
Hi,

the following patch adds fix-it hints to the C++ parser for two wrongly
used keywords detected in cp_parser_decl_specifier_seq.

Bootstrapped and regtested on x86_64-pc-linux-gnu.

OK for trunk?

Regards,
Volker


2017-04-29  Volker Reichelt  <v.reich...@netcologne.de>

        * parser.c (cp_parser_decl_specifier_seq): Add fix-it hints for
        friend outside class and obsolete auto as storage-class-specifier.

Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c     2017-04-28
+++ gcc/cp/parser.c     2017-04-28
@@ -13213,7 +13213,9 @@
        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
@@ -13277,8 +13279,11 @@

               /* 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");
+             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");

What caught my eye here is the "please remove it" part :)  Maybe
it's me but it seems a little too forceful for a warning (despite
the please).  I would find a more conventional phrasing like
"suggest to remove it" to be more suitable.

That said, I wonder if removing the auto is actually the best
suggestion.  Wouldn't it more in line with where C++ is headed
to suggest to remove the type and keep the auto?

Martin

Reply via email to