libstdc++: Fix std::reverse_iterator comparisons (PR 94354)
authorJonathan Wakely <jwakely@redhat.com>
Wed, 27 May 2020 20:58:56 +0000 (21:58 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 27 May 2020 20:58:56 +0000 (21:58 +0100)
commit979e89a9a94f66241fa8355e2b2e8f4a680c83e1
tree4b5847f39a85c3f6ee3d1b8dd3c9f718b99301a2
parent1852a26b925970f64f8d31518ba732fe9c3ade23
libstdc++: Fix std::reverse_iterator comparisons (PR 94354)

The std::reverse_iterator comparisons have always been implemented only
in terms of equality and less than. In C++98 that made no difference for
reasonable code, because when the underlying operators are the same type
they are required to support all comparisons anyway.

But since LWG 280 it's possible to compare reverse_iterator<X> and
reverse_iterator<Y>, and comparisons between X and Y might not support
the full set of equality and relational operators. This means that it
matters whether we implement operator!= as x.base() != y.base() or
!(x.base() == y.base()), and the current implementation is
non-conforming.

This was already fixed in GCC 10.1 for C++20, this change also fixes it
for all other -std modes.

PR libstdc++/94354
* include/bits/stl_iterator.h (reverse_iterator): Fix comparison
operators to use the correct operations on the underlying
iterators.
* testsuite/24_iterators/reverse_iterator/rel_ops.cc: New test.
libstdc++-v3/include/bits/stl_iterator.h
libstdc++-v3/testsuite/24_iterators/reverse_iterator/rel_ops.cc [new file with mode: 0644]