public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100639] New: reverse_view<I>::reference erroneously uses iterator_traits<I>::reference instead of iter_reference_t<I>
@ 2021-05-17 16:50 barry.revzin at gmail dot com
  2021-05-17 18:03 ` [Bug c++/100639] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: barry.revzin at gmail dot com @ 2021-05-17 16:50 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-06-10 18:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 16:50 [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
2021-05-17 18:03 ` [Bug c++/100639] " redi at gcc dot gnu.org
2021-05-18 18:22 ` [Bug libstdc++/100639] reverse_iterator<I>::reference " ppalka at gcc dot gnu.org
2021-05-18 19:42 ` ppalka at gcc dot gnu.org
2021-05-20 18:11 ` cvs-commit at gcc dot gnu.org
2021-06-10 18:43 ` cvs-commit at gcc dot gnu.org
2021-06-10 18:49 ` cvs-commit at gcc dot gnu.org
2021-06-10 18:50 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).