public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rs2740 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/100479] New: range adaptors handle cached iterators incorrectly
Date: Fri, 07 May 2021 23:04:55 +0000	[thread overview]
Message-ID: <bug-100479-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100479

            Bug ID: 100479
           Summary: range adaptors handle cached iterators incorrectly
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rs2740 at gmail dot com
  Target Milestone: ---

template<forward_range _Range>
      struct _CachedPosition<_Range>
      {
      private:
        iterator_t<_Range> _M_iter{};

      public:
        constexpr bool
        _M_has_value() const
        { return _M_iter != iterator_t<_Range>{}; }

        constexpr iterator_t<_Range>
        _M_get(const _Range&) const
        {
          __glibcxx_assert(_M_has_value());
          return _M_iter;
        }

        constexpr void
        _M_set(const _Range&, const iterator_t<_Range>& __it)
        {
          __glibcxx_assert(!_M_has_value());
          _M_iter = __it;
        }
      };

- The domain of == for forward iterators is limited to iterators over the same
underlying sequence. While value-initialized forward iterators of the same type
may be compared against each other, comparing them against iterators into other
ranges is not required to be well-defined, so it cannot be used as a sentinel
value.
- The cache cannot be allowed to propagate when the view containing it is
copied/moved, and has to be invalidated when the view containing it is moved.
Any cached iterator points to the original underlying view, and not the new
one; also, moving from a view can change its value (if it is well-defined to
use the moved-from view), so the cache is no longer valid. (Handling this case
correctly was actually the original use case for non-propagating-cache in
range-v3.)

             reply	other threads:[~2021-05-07 23:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-07 23:04 rs2740 at gmail dot com [this message]
2021-05-07 23:09 ` [Bug libstdc++/100479] " redi at gcc dot gnu.org
2021-05-11 15:28 ` ppalka at gcc dot gnu.org
2021-05-24 19:24 ` cvs-commit at gcc dot gnu.org
2021-05-28 14:21 ` cvs-commit at gcc dot gnu.org
2021-10-12 19:00 ` 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-100479-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).