[RFC/PATCH] Use range-based for loops for traversing loops

Jonathan Wakely jwakely.gcc@gmail.com
Mon Jul 19 14:08:38 GMT 2021


On Mon, 19 Jul 2021 at 07:20, Kewen.Lin <linkw@linux.ibm.com> wrote:
>
> Hi,
>
> This patch follows Martin's suggestion here[1], to support
> range-based for loops for traversing loops, analogously to
> the patch for vec[2].
>
> Bootstrapped and regtested on powerpc64le-linux-gnu P9,
> x86_64-redhat-linux and aarch64-linux-gnu, also
> bootstrapped on ppc64le P9 with bootstrap-O3 config.
>
> Any comments are appreciated.

In the loops_list::iterator type, this looks a little strange:

+    bool
+    operator!= (const iterator &rhs) const
+    {
+      return this->curr_idx < rhs.curr_idx;
+    }
+

This works fine when the iterator type is used implicitly in a
range-based for loop, but it wouldn't work for explicit uses of the
iterator type where somebody does the != comparison with the
past-the-end iterator on on the LHS:

auto&& list ALL_LOOPS(foo);
auto end = list.end();
auto begin = list.begin();
while (--end != begin)


More information about the Gcc-patches mailing list