]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix view adaptors for mixed-const sentinels and iterators (PR 95322)
authorJonathan Wakely <jwakely@redhat.com>
Wed, 27 May 2020 21:08:15 +0000 (22:08 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 9 Jul 2020 10:01:03 +0000 (11:01 +0100)
commit38250e577e26de7aace65b4d32a94a1404f076a9
tree5aa578ea255a7448140f6a190b7ea1245019e50c
parent6b19640035d2df46758c7d31e5aab1186518e514
libstdc++: Fix view adaptors for mixed-const sentinels and iterators (PR 95322)

The bug report is that transform_view's sentinel<false> cannot be
compared to its iterator<true>.  The comparison is supposed to use
operator==(iterator<Const>, sentinel<Const>) after converting
sentinel<false> to sentinel<true>. However, the operator== is a hidden
friend so is not a candidate when comparing iterator<true> with
sentinel<false>. The required conversion would only happen if we'd found
the operator, but we can't find the operator until after the conversion
happens.

A new LWG issue has been reported, but not yet assigned a number.  The
solution suggested by Casey Carter is to make the hidden friends of the
sentinel types work with iterators of any const-ness, so that no
conversions are required.

Patrick Palka observed that join_view has a similar problem and a
similar fix is used for its sentinel.

PR libstdc++/95322
* include/std/ranges (transform_view::_Sentinel): Allow hidden
friends to work with _Iterator<true> and _Iterator<false>.
(join_view::_Sentinel): Likewise.
* testsuite/std/ranges/adaptors/95322.cc: New test.

(cherry picked from commit 6c2582c0406250c66e2eb3651f8e8638796b7f53)
libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/adaptors/95322.cc