[Bug c++/100639] New: reverse_view<I>::reference erroneously uses iterator_traits<I>::reference instead of iter_reference_t<I>
barry.revzin at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon May 17 16:50:08 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100639
Bug ID: 100639
Summary: reverse_view<I>::reference erroneously uses
iterator_traits<I>::reference instead of
iter_reference_t<I>
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: barry.revzin at gmail dot com
Target Milestone: ---
Short example (from https://stackoverflow.com/q/67573305/2069064):
#include <ranges>
template <typename T> using iota = std::ranges::iota_view<T, T>;
template <typename T> using iota_iter = std::ranges::iterator_t<iota<T>>;
static_assert(std::same_as<
std::reverse_iterator<iota_iter<int64_t>>::reference,
int64_t>);
This assertion fails when compiling with -std=c++20 (because the reference type
is 'void') but passes with -std=gnu++20. The direct reason is that the
difference_type of the iota_view iterator is __int128, which is considered a
signed_integral with gnu++20 but not c++20.
But the reason this matters is because std::reverse_iterator<I>::reference is
defined as std::iterator_traits<I>::reference (which checks that I satsifies
cpp17-input-iterator which has the signed_integral constraint) instead of being
defined as std::iter_reference_t<I> (which has no such check). With the latter
implementation, the assertion above would pass on either version.
The result is that reversing an iota_view<int64_t, int64_t> isn't a range on
-std=c++20.
More information about the Gcc-bugs
mailing list