public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "barry.revzin at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/100639] New: reverse_view<I>::reference erroneously uses iterator_traits<I>::reference instead of iter_reference_t<I>
Date: Mon, 17 May 2021 16:50:08 +0000	[thread overview]
Message-ID: <bug-100639-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2021-05-17 16:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17 16:50 barry.revzin at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-100639-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).