]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: use range-for more
authorJason Merrill <jason@redhat.com>
Sat, 23 Oct 2021 09:45:02 +0000 (05:45 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 4 Nov 2021 15:35:54 +0000 (11:35 -0400)
gcc/cp/ChangeLog:

* call.c (build_array_conv): Use range-for.
(build_complex_conv): Likewise.
* constexpr.c (clear_no_implicit_zero)
(reduced_constant_expression_p): Likewise.
* decl.c (cp_complete_array_type): Likewise.
* decl2.c (mark_vtable_entries): Likewise.
* pt.c (iterative_hash_template_arg):
(invalid_tparm_referent_p, unify)
(type_dependent_expression_p): Likewise.
* typeck.c (build_ptrmemfunc_access_expr): Likewise.

gcc/cp/call.c
gcc/cp/constexpr.c
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/cp/pt.c
gcc/cp/typeck.c

index 20e66c6c63f3c504052044e1a03c88a42df656a6..01ac114a62c83c2252b82bbe1d6f774d3f47d0e2 100644 (file)
@@ -1070,8 +1070,6 @@ build_array_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
   conversion *c;
   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
   tree elttype = TREE_TYPE (type);
-  unsigned i;
-  tree val;
   bool bad = false;
   bool user = false;
   enum conversion_rank rank = cr_exact;
@@ -1089,10 +1087,10 @@ build_array_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
 
   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
 
-  FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
+  for (auto &e: CONSTRUCTOR_ELTS (ctor))
     {
       conversion *sub
-       = implicit_conversion (elttype, TREE_TYPE (val), val,
+       = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
                               false, flags, complain);
       if (sub == NULL)
        return NULL;
@@ -1124,8 +1122,6 @@ build_complex_conv (tree type, tree ctor, int flags,
   conversion *c;
   unsigned HOST_WIDE_INT len = CONSTRUCTOR_NELTS (ctor);
   tree elttype = TREE_TYPE (type);
-  unsigned i;
-  tree val;
   bool bad = false;
   bool user = false;
   enum conversion_rank rank = cr_exact;
@@ -1135,10 +1131,10 @@ build_complex_conv (tree type, tree ctor, int flags,
 
   flags = LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING;
 
-  FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
+  for (auto &e: CONSTRUCTOR_ELTS (ctor))
     {
       conversion *sub
-       = implicit_conversion (elttype, TREE_TYPE (val), val,
+       = implicit_conversion (elttype, TREE_TYPE (e.value), e.value,
                               false, flags, complain);
       if (sub == NULL)
        return NULL;
index 40fe165c2b7c8758bf3c4a15a645b99b7c8a5953..453007c686bf0400cec2f3abe396c5d56b33ecea 100644 (file)
@@ -1831,10 +1831,9 @@ clear_no_implicit_zero (tree ctor)
   if (CONSTRUCTOR_NO_CLEARING (ctor))
     {
       CONSTRUCTOR_NO_CLEARING (ctor) = false;
-      tree elt; unsigned HOST_WIDE_INT idx;
-      FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), idx, elt)
-       if (TREE_CODE (elt) == CONSTRUCTOR)
-         clear_no_implicit_zero (elt);
+      for (auto &e: CONSTRUCTOR_ELTS (ctor))
+       if (TREE_CODE (e.value) == CONSTRUCTOR)
+         clear_no_implicit_zero (e.value);
     }
 }
 
@@ -2950,7 +2949,7 @@ reduced_constant_expression_p (tree t)
 
     case CONSTRUCTOR:
       /* And we need to handle PTRMEM_CST wrapped in a CONSTRUCTOR.  */
-      tree idx, val, field; unsigned HOST_WIDE_INT i;
+      tree field;
       if (CONSTRUCTOR_NO_CLEARING (t))
        {
          if (TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
@@ -2964,14 +2963,14 @@ reduced_constant_expression_p (tree t)
              tree min = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (t)));
              tree max = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (t)));
              tree cursor = min;
-             FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), i, idx, val)
+             for (auto &e: CONSTRUCTOR_ELTS (t))
                {
-                 if (!reduced_constant_expression_p (val))
+                 if (!reduced_constant_expression_p (e.value))
                    return false;
-                 if (array_index_cmp (cursor, idx) != 0)
+                 if (array_index_cmp (cursor, e.index) != 0)
                    return false;
-                 if (TREE_CODE (idx) == RANGE_EXPR)
-                   cursor = TREE_OPERAND (idx, 1);
+                 if (TREE_CODE (e.index) == RANGE_EXPR)
+                   cursor = TREE_OPERAND (e.index, 1);
                  cursor = int_const_binop (PLUS_EXPR, cursor, size_one_node);
                }
              if (find_array_ctor_elt (t, max) == -1)
@@ -2992,14 +2991,14 @@ reduced_constant_expression_p (tree t)
        }
       else
        field = NULL_TREE;
-      FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), i, idx, val)
+      for (auto &e: CONSTRUCTOR_ELTS (t))
        {
          /* If VAL is null, we're in the middle of initializing this
             element.  */
-         if (!reduced_constant_expression_p (val))
+         if (!reduced_constant_expression_p (e.value))
            return false;
          /* Empty class field may or may not have an initializer.  */
-         for (; field && idx != field;
+         for (; field && e.index != field;
               field = next_initializable_field (DECL_CHAIN (field)))
            if (!is_really_empty_class (TREE_TYPE (field),
                                        /*ignore_vptr*/false))
index 7c2a134e40614e43da8ea4e83cfcac8280369f8f..947bbfc66377c51d81a1aba658dcf562aa818e5c 100644 (file)
@@ -9538,9 +9538,6 @@ cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
 
   if (initial_value)
     {
-      unsigned HOST_WIDE_INT i;
-      tree value;
-
       /* An array of character type can be initialized from a
         brace-enclosed string constant.
 
@@ -9562,14 +9559,9 @@ cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
       /* If any of the elements are parameter packs, we can't actually
         complete this type now because the array size is dependent.  */
       if (TREE_CODE (initial_value) == CONSTRUCTOR)
-       {
-         FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (initial_value), 
-                                     i, value)
-           {
-             if (PACK_EXPANSION_P (value))
-               return 0;
-           }
-       }
+       for (auto &e: CONSTRUCTOR_ELTS (initial_value))
+         if (PACK_EXPANSION_P (e.value))
+           return 0;
     }
 
   failure = complete_array_type (ptype, initial_value, do_default);
index a79a70ba9c2f94666298cbf87276ac23dbb7fd40..32d3fe3636d095019710d064092deaaf3b9ce4f2 100644 (file)
@@ -1913,18 +1913,14 @@ coerce_delete_type (tree decl, location_t loc)
 static void
 mark_vtable_entries (tree decl, vec<tree> &consteval_vtables)
 {
-  tree fnaddr;
-  unsigned HOST_WIDE_INT idx;
-
   /* It's OK for the vtable to refer to deprecated virtual functions.  */
   warning_sentinel w(warn_deprecated_decl);
 
   bool consteval_seen = false;
 
-  FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)),
-                             idx, fnaddr)
+  for (auto &e: CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
     {
-      tree fn;
+      tree fnaddr = e.value;
 
       STRIP_NOPS (fnaddr);
 
@@ -1934,7 +1930,7 @@ mark_vtable_entries (tree decl, vec<tree> &consteval_vtables)
           virtual call offset, an RTTI offset, etc.  */
        continue;
 
-      fn = TREE_OPERAND (fnaddr, 0);
+      tree fn = TREE_OPERAND (fnaddr, 0);
       if (TREE_CODE (fn) == FUNCTION_DECL && DECL_IMMEDIATE_FUNCTION_P (fn))
        {
          if (!consteval_seen)
index 66040035b2fba83aac52720dc82c1e0bf9c854f2..2638d3ce3d4bb44e3147182352fe9626f496b16c 100644 (file)
@@ -1831,13 +1831,11 @@ iterative_hash_template_arg (tree arg, hashval_t val)
 
     case CONSTRUCTOR:
       {
-       tree field, value;
-       unsigned i;
        iterative_hash_template_arg (TREE_TYPE (arg), val);
-       FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (arg), i, field, value)
+       for (auto &e: CONSTRUCTOR_ELTS (arg))
          {
-           val = iterative_hash_template_arg (field, val);
-           val = iterative_hash_template_arg (value, val);
+           val = iterative_hash_template_arg (e.index, val);
+           val = iterative_hash_template_arg (e.value, val);
          }
        return val;
       }
@@ -7004,9 +7002,8 @@ invalid_tparm_referent_p (tree type, tree expr, tsubst_flags_t complain)
 
     case CONSTRUCTOR:
       {
-       unsigned i; tree elt;
-       FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), i, elt)
-         if (invalid_tparm_referent_p (TREE_TYPE (elt), elt, complain))
+       for (auto &e: CONSTRUCTOR_ELTS (expr))
+         if (invalid_tparm_referent_p (TREE_TYPE (e.value), e.value, complain))
            return true;
       }
       break;
@@ -23605,8 +23602,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
      we're dealing with a type. */
   if (BRACE_ENCLOSED_INITIALIZER_P (arg))
     {
-      tree elt, elttype;
-      unsigned i;
+      tree elttype;
       tree orig_parm = parm;
 
       if (!is_std_init_list (parm)
@@ -23633,8 +23629,9 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
        /* If ELTTYPE has no deducible template parms, skip deduction from
           the list elements.  */;
       else
-       FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (arg), i, elt)
+       for (auto &e: CONSTRUCTOR_ELTS (arg))
          {
+           tree elt = e.value;
            int elt_strict = strict;
 
            if (elt == error_mark_node)
@@ -27420,14 +27417,9 @@ type_dependent_expression_p (tree expression)
 
   if (BRACE_ENCLOSED_INITIALIZER_P (expression))
     {
-      tree elt;
-      unsigned i;
-
-      FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expression), i, elt)
-       {
-         if (type_dependent_expression_p (elt))
-           return true;
-       }
+      for (auto &elt : CONSTRUCTOR_ELTS (expression))
+       if (type_dependent_expression_p (elt.value))
+         return true;
       return false;
     }
 
index d5f50001dc093ce35ac999d0f62551618abef0eb..cb20329ceb57ca188ffaac95df7baddba8ae5ef5 100644 (file)
@@ -3460,12 +3460,9 @@ build_ptrmemfunc_access_expr (tree ptrmem, tree member_name)
 
   if (TREE_CODE (ptrmem) == CONSTRUCTOR)
     {
-      unsigned int ix;
-      tree index, value;
-      FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ptrmem),
-                               ix, index, value)
-       if (index && DECL_P (index) && DECL_NAME (index) == member_name)
-         return value;
+      for (auto &e: CONSTRUCTOR_ELTS (ptrmem))
+       if (e.index && DECL_P (e.index) && DECL_NAME (e.index) == member_name)
+         return e.value;
       gcc_unreachable ();
     }