[C++ PATCH] Deprecate ARM-era for scopes
authorNathan Sidwell <nathan@acm.org>
Tue, 23 Jan 2018 12:18:50 +0000 (12:18 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Tue, 23 Jan 2018 12:18:50 +0000 (12:18 +0000)
https://gcc.gnu.org/ml/gcc-patches/2018-01/msg01940.html
gcc/cp/
Deprecate ARM-era for scope handling
* decl.c (poplevel): Flag_new_for_scope is a boolean-like.
(cxx_init_decl_processing): Deprecate flag_new_for_scope being
cleared.
* name-lookup.c (check_for_out_of_scope_variable): Deprecate and
cleanup handling.
* semantics.c (begin_for_scope): Flag_new_for_scope is
boolean-like.
(finish_for_stmt, begin_range_for_stmt): Likewise.

gcc/
* doc/invoke.texi (ffor-scope): Deprecate.

gcc/cp/
* g++.dg/cpp0x/range-for10.C: Adjust.
* g++.dg/ext/forscope1.C: Adjust.
* g++.dg/ext/forscope2.C: Adjust.
* g++.dg/template/for1.C: Adjust.

From-SVN: r256981

gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/name-lookup.c
gcc/cp/semantics.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/range-for10.C
gcc/testsuite/g++.dg/ext/forscope1.C
gcc/testsuite/g++.dg/ext/forscope2.C
gcc/testsuite/g++.dg/template/for1.C

index 6718a38..9cda294 100644 (file)
@@ -1,3 +1,7 @@
+2018-01-23  Nathan Sidwell  <nathan@acm.org>
+
+       * doc/invoke.texi (ffor-scope): Deprecate.
+
 2018-01-23  David Malcolm  <dmalcolm@redhat.com>
 
        PR tree-optimization/83510
index 004d234..bd15f4c 100644 (file)
@@ -1,3 +1,15 @@
+2018-01-23  Nathan Sidwell  <nathan@acm.org>
+
+       Deprecate ARM-era for scope handling
+       * decl.c (poplevel): Flag_new_for_scope is a boolean-like.
+       (cxx_init_decl_processing): Deprecate flag_new_for_scope being
+       cleared.
+       * name-lookup.c (check_for_out_of_scope_variable): Deprecate and
+       cleanup handling.
+       * semantics.c (begin_for_scope): Flag_new_for_scope is
+       boolean-like.
+       (finish_for_stmt, begin_range_for_stmt): Likewise.
+
 2018-01-22  Jason Merrill  <jason@redhat.com>
 
        PR c++/83720
index 230e7dd..f6fab42 100644 (file)
@@ -644,7 +644,7 @@ poplevel (int keep, int reverse, int functionbody)
      in a init statement were in scope after the for-statement ended.
      We only use the new rules if flag_new_for_scope is nonzero.  */
   leaving_for_scope
-    = current_binding_level->kind == sk_for && flag_new_for_scope == 1;
+    = current_binding_level->kind == sk_for && flag_new_for_scope;
 
   /* Before we remove the declarations first check for unused variables.  */
   if ((warn_unused_variable || warn_unused_but_set_variable)
@@ -4094,6 +4094,8 @@ cxx_init_decl_processing (void)
   pop_namespace ();
 
   flag_noexcept_type = (cxx_dialect >= cxx17);
+  if (!flag_new_for_scope)
+    warning (OPT_Wdeprecated, "%<-fno-for-scope%> is deprecated");
 
   c_common_nodes_and_builtins ();
 
index 8d34293..c37e522 100644 (file)
@@ -3231,7 +3231,9 @@ push_local_binding (tree id, tree decl, bool is_using)
    standard.  If so, issue an error message.  If name lookup would
    work in both cases, but return a different result, this function
    returns the result of ANSI/ISO lookup.  Otherwise, it returns
-   DECL.  */
+   DECL.
+
+   FIXME: Scheduled for removal after GCC-8 is done.  */
 
 tree
 check_for_out_of_scope_variable (tree decl)
@@ -3252,16 +3254,16 @@ check_for_out_of_scope_variable (tree decl)
     shadowed = find_namespace_value (current_namespace, DECL_NAME (decl));
   if (shadowed)
     {
-      if (!DECL_ERROR_REPORTED (decl))
+      if (!DECL_ERROR_REPORTED (decl)
+         && flag_permissive
+         && warning (0, "name lookup of %qD changed", DECL_NAME (decl)))
        {
-         warning (0, "name lookup of %qD changed", DECL_NAME (decl));
-         warning_at (DECL_SOURCE_LOCATION (shadowed), 0,
-                     "  matches this %qD under ISO standard rules",
-                     shadowed);
-         warning_at (DECL_SOURCE_LOCATION (decl), 0,
-                     "  matches this %qD under old rules", decl);
-         DECL_ERROR_REPORTED (decl) = 1;
+         inform (DECL_SOURCE_LOCATION (shadowed),
+                 "matches this %qD under ISO standard rules", shadowed);
+         inform (DECL_SOURCE_LOCATION (decl),
+                 "  matches this %qD under old rules", decl);
        }
+      DECL_ERROR_REPORTED (decl) = 1;
       return shadowed;
     }
 
@@ -3279,26 +3281,25 @@ check_for_out_of_scope_variable (tree decl)
     {
       error ("name lookup of %qD changed for ISO %<for%> scoping",
             DECL_NAME (decl));
-      error ("  cannot use obsolete binding at %q+D because "
-            "it has a destructor", decl);
+      inform (DECL_SOURCE_LOCATION (decl),
+             "cannot use obsolete binding %qD because it has a destructor",
+             decl);
       return error_mark_node;
     }
   else
     {
-      permerror (input_location, "name lookup of %qD changed for ISO %<for%> scoping",
+      permerror (input_location,
+                "name lookup of %qD changed for ISO %<for%> scoping",
                 DECL_NAME (decl));
       if (flag_permissive)
-        permerror (DECL_SOURCE_LOCATION (decl),
-                  "  using obsolete binding at %qD", decl);
-      else
-       {
-         static bool hint;
-         if (!hint)
-           {
-             inform (input_location, "(if you use %<-fpermissive%> G++ will accept your code)");
-             hint = true;
-           }
-       }
+        inform (DECL_SOURCE_LOCATION (decl),
+               "using obsolete binding %qD", decl);
+      static bool hint;
+      if (!hint)
+       inform (input_location, flag_permissive
+               ? "this flexibility is deprecated and will be removed"
+               : "if you use %<-fpermissive%> G++ will accept your code");
+      hint = true;
     }
 
   return decl;
index f9c5285..b758051 100644 (file)
@@ -931,7 +931,7 @@ tree
 begin_for_scope (tree *init)
 {
   tree scope = NULL_TREE;
-  if (flag_new_for_scope > 0)
+  if (flag_new_for_scope)
     scope = do_pushlevel (sk_for);
 
   if (processing_template_decl)
@@ -956,7 +956,7 @@ begin_for_stmt (tree scope, tree init)
 
   if (scope == NULL_TREE)
     {
-      gcc_assert (!init || !(flag_new_for_scope > 0));
+      gcc_assert (!init || !flag_new_for_scope);
       if (!init)
        scope = begin_for_scope (&init);
     }
@@ -1053,7 +1053,7 @@ finish_for_stmt (tree for_stmt)
     FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
 
   /* Pop the scope for the body of the loop.  */
-  if (flag_new_for_scope > 0)
+  if (flag_new_for_scope)
     {
       tree scope;
       tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
@@ -1082,7 +1082,7 @@ begin_range_for_stmt (tree scope, tree init)
 
   if (scope == NULL_TREE)
     {
-      gcc_assert (!init || !(flag_new_for_scope > 0));
+      gcc_assert (!init || !flag_new_for_scope);
       if (!init)
        scope = begin_for_scope (&init);
     }
index 27c5974..891de73 100644 (file)
@@ -2467,9 +2467,8 @@ a @i{for-init-statement} extends to the end of the enclosing scope,
 as was the case in old versions of G++, and other (traditional)
 implementations of C++.
 
-If neither flag is given, the default is to follow the standard,
-but to allow and give a warning for old-style code that would
-otherwise be invalid, or have different behavior.
+This option is deprecated and the associated non-standard
+functionality will be removed.
 
 @item -fno-gnu-keywords
 @opindex fno-gnu-keywords
index 827bcba..bcbaa4c 100644 (file)
@@ -1,3 +1,10 @@
+2018-01-23  Nathan Sidwell  <nathan@acm.org>
+
+       * g++.dg/cpp0x/range-for10.C: Adjust.
+       * g++.dg/ext/forscope1.C: Adjust.
+       * g++.dg/ext/forscope2.C: Adjust.
+       * g++.dg/template/for1.C: Adjust.
+
 2018-01-23  David Malcolm  <dmalcolm@redhat.com>
 
        PR tree-optimization/83510
index 1397830..7288a3b 100644 (file)
@@ -1,6 +1,6 @@
 // PR c++/47388
 // { dg-do compile { target c++11 } }
-// { dg-options "-fno-for-scope" }
+// { dg-options "-fno-for-scope -Wno-deprecated" }
 
 template <int>
 void
index fa6401a..cf0cb2c 100644 (file)
@@ -1,5 +1,5 @@
 // { dg-do compile }
-// { dg-options -fno-for-scope }
+// { dg-options "-fno-for-scope -Wno-deprecated" }
 
 // Copyright (C) 2001 Free Software Foundation, Inc.
 // Contributed by Nathan Sidwell 4 Sept 2001 <nathan@codesourcery.com>
index 460b240..3490d3f 100644 (file)
@@ -16,7 +16,7 @@ struct A
 
 void Go( )
 {
-  for (int i = 1;;)    // { dg-warning "using obsolete binding" }
+  for (int i = 1;;)    // { dg-message "using obsolete binding" }
     {
       switch (1) {
       default: {}
index dc33afc..ebb4445 100644 (file)
@@ -1,6 +1,6 @@
 // PR c++/47388
 // { dg-do compile }
-// { dg-options "-fno-for-scope" }
+// { dg-options "-fno-for-scope -Wno-deprecated" }
 
 template <int>
 void