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

            Bug ID: 93960
           Summary: std::to_address doesn't work with past-the-end Debug
                    Mode iterators
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

// -std=gnu++2a
#define _GLIBCXX_DEBUG
#include <vector>

int main()
{
  std::vector<int> v{1, 2, 3};
  (void) std::to_address(v.end());
}

This aborts:

/home/jwakely/gcc/10/include/c++/10.0.1/debug/safe_iterator.h:311:
In function:
    __gnu_debug::_Safe_iterator<_Iterator, _Sequence, _Category>::pointer 
    __gnu_debug::_Safe_iterator<_Iterator, _Sequence, 
    _Category>::operator->() const [with _Iterator = 
    __gnu_cxx::__normal_iterator<int*, std::__cxx1998::vector<int, 
    std::allocator<int> > >; _Sequence = std::__debug::vector<int>; 
    _Category = std::forward_iterator_tag; 
    __gnu_debug::_Safe_iterator<_Iterator, _Sequence, _Category>::pointer = 
    int*]

Error: attempt to dereference a past-the-end iterator.

Objects involved in the operation:
    iterator "this" @ 0x0x7ffca2d5b330 {
      type = __gnu_cxx::__normal_iterator<int*, std::__cxx1998::vector<int,
std::allocator<int> > > (mutable iterator);
      state = past-the-end;
      references sequence with type 'std::__debug::vector<int,
std::allocator<int> >' @ 0x0x7ffca2d5b2e0
    }
Aborted (core dumped)


We probably do want to be able to assert in operator-> so that we catch things
like end->foo() but we also need std::to_address to work.

The solution might be to overload std::to_address for our safe iterators, so
that it returns the _Base::operator->() pointer without doing the assertions.

Reply via email to