public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100479] New: range adaptors handle cached iterators incorrectly
@ 2021-05-07 23:04 rs2740 at gmail dot com
  2021-05-07 23:09 ` [Bug libstdc++/100479] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: rs2740 at gmail dot com @ 2021-05-07 23:04 UTC (permalink / raw)
  To: gcc-bugs

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.)

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

end of thread, other threads:[~2021-10-12 19:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 23:04 [Bug libstdc++/100479] New: range adaptors handle cached iterators incorrectly rs2740 at gmail dot com
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

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).