aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/call.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-03-02 16:30:41 -0500
committerJason Merrill <jason@redhat.com>2021-05-01 05:45:06 -0400
commit3307b9a07a3c515c6805d435e4bedada77687183 (patch)
treeb78aa228c7c0c568b647be2091a969c86cd736df /gcc/cp/call.c
parent3c65858787dc52b65b26fa7018587c01510f442c (diff)
downloadgcc-3307b9a07a3c515c6805d435e4bedada77687183.zip
gcc-3307b9a07a3c515c6805d435e4bedada77687183.tar.gz
gcc-3307b9a07a3c515c6805d435e4bedada77687183.tar.bz2
c++: C++11 range-for and ovl/lkp_iterator
We can't use C++11 range-based 'for' over a tree directly, because we don't know what kind of range we want to use it as. I suppose in some cases we could guess, but it seems better to tersely make it explicit. This patch adds range adaptors ovl_range and lkp_range for use as the range of a range-for, e.g. for (tree fn : lkp_range (fns)) { ... } This patch also removes the private copy ops from ovl_iterator; it's necessary for range-for, and these are effectively C++ forward_iterators, which allow copying, so I don't see a reason to prevent it. A bit more would need to be done to make them actually conform as C++11 forward iterators, but I don't think we particularly want to #include <iterator> yet. gcc/cp/ChangeLog: * cp-tree.h (class ovl_iterator): Allow copying. Add op==. (class ovl_range, class lkp_range): New. * call.c (build_op_call_1, add_candidates): Use them. (build_op_delete_call, has_trivial_copy_assign_p): Likewise. (has_trivial_copy_p): Likewise. * class.c (handle_using_decl, get_basefndecls): Likewise. (maybe_warn_about_overly_private_class): Likewise. (warn_hidden, add_implicitly_declared_members): Likewise. (check_methods, clone_constructors_and_destructors): Likewise. (type_has_user_nondefault_constructor): Likewise.
Diffstat (limited to 'gcc/cp/call.c')
-rw-r--r--gcc/cp/call.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 678e120a..57bac05 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4914,10 +4914,8 @@ build_op_call_1 (tree obj, vec<tree, va_gc> **args, tsubst_flags_t complain)
|| TYPE_REFFN_P (totype)
|| (TYPE_REF_P (totype)
&& TYPE_PTRFN_P (TREE_TYPE (totype))))
- for (ovl_iterator iter (TREE_VALUE (convs)); iter; ++iter)
+ for (tree fn : ovl_range (TREE_VALUE (convs)))
{
- tree fn = *iter;
-
if (DECL_NONCONVERTING_P (fn))
continue;
@@ -5981,10 +5979,8 @@ add_candidates (tree fns, tree first_arg, const vec<tree, va_gc> *args,
which = non_templates;
again:
- for (lkp_iterator iter (fns); iter; ++iter)
+ for (tree fn : lkp_range (fns))
{
- fn = *iter;
-
if (check_converting && DECL_NONCONVERTING_P (fn))
continue;
if (check_list_ctor && !is_list_ctor (fn))
@@ -7016,10 +7012,8 @@ build_op_delete_call (enum tree_code code, tree addr, tree size,
the usual deallocation function, so we shouldn't complain
about using the operator delete (void *, size_t). */
if (DECL_CLASS_SCOPE_P (fn))
- for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns));
- iter; ++iter)
+ for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
{
- tree elt = *iter;
if (usual_deallocation_fn_p (elt)
&& FUNCTION_ARG_CHAIN (elt) == void_list_node)
goto ok;
@@ -7062,9 +7056,8 @@ build_op_delete_call (enum tree_code code, tree addr, tree size,
allocation function. If the lookup finds a single matching
deallocation function, that function will be called; otherwise, no
deallocation function will be called." */
- for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
+ for (tree elt : lkp_range (MAYBE_BASELINK_FUNCTIONS (fns)))
{
- tree elt = *iter;
dealloc_info di_elt;
if (usual_deallocation_fn_p (elt, &di_elt))
{
@@ -9669,10 +9662,8 @@ has_trivial_copy_assign_p (tree type, bool access, bool *hasassign)
/* Iterate over overloads of the assignment operator, checking
accessible copy assignments for triviality. */
- for (ovl_iterator oi (fns); oi; ++oi)
+ for (tree f : ovl_range (fns))
{
- tree f = *oi;
-
/* Skip operators that aren't copy assignments. */
if (!copy_fn_p (f))
continue;
@@ -9715,10 +9706,8 @@ has_trivial_copy_p (tree type, bool access, bool hasctor[2])
tree fns = get_class_binding (type, complete_ctor_identifier);
bool all_trivial = true;
- for (ovl_iterator oi (fns); oi; ++oi)
+ for (tree f : ovl_range (fns))
{
- tree f = *oi;
-
/* Skip template constructors. */
if (TREE_CODE (f) != FUNCTION_DECL)
continue;