diff options
author | Jason Merrill <jason@redhat.com> | 2021-10-23 05:45:02 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-11-04 11:35:54 -0400 |
commit | fae00a0ac0e5687343a60ae02bf60352002ab9aa (patch) | |
tree | b929b52de9cd73a11c5fcf2848b8ea23a84e009d | |
parent | eb04ccf4bfd6586cf0d22d439de28a4e6c649182 (diff) | |
download | gcc-fae00a0ac0e5687343a60ae02bf60352002ab9aa.zip gcc-fae00a0ac0e5687343a60ae02bf60352002ab9aa.tar.gz gcc-fae00a0ac0e5687343a60ae02bf60352002ab9aa.tar.bz2 |
c++: use range-for more
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.
-rw-r--r-- | gcc/cp/call.c | 12 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 25 | ||||
-rw-r--r-- | gcc/cp/decl.c | 14 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 10 | ||||
-rw-r--r-- | gcc/cp/pt.c | 30 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 9 |
6 files changed, 36 insertions, 64 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 20e66c6..01ac114 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -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; diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 40fe165..453007c 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -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)) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 7c2a134..947bbfc 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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); diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index a79a70b..32d3fe3 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -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) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6604003..2638d3c 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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; } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index d5f5000..cb20329 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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 (); } |