]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: C++11 range-for and ovl/lkp_iterator
authorJason Merrill <jason@redhat.com>
Tue, 2 Mar 2021 21:30:41 +0000 (16:30 -0500)
committerJason Merrill <jason@redhat.com>
Sat, 1 May 2021 09:45:06 +0000 (05:45 -0400)
commit3307b9a07a3c515c6805d435e4bedada77687183
treeb78aa228c7c0c568b647be2091a969c86cd736df
parent3c65858787dc52b65b26fa7018587c01510f442c
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.
gcc/cp/call.c
gcc/cp/class.c
gcc/cp/cp-tree.h