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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's also diagnosed by libstdc++ Debug Mode:

/home/jwakely/gcc/10/include/c++/10.0.0/debug/safe_iterator.h:294:
In function:
    __gnu_debug::_Safe_iterator<_Iterator, _Sequence, _Category>::reference 
    __gnu_debug::_Safe_iterator<_Iterator, _Sequence, 
    _Category>::operator*() const [with _Iterator = 
    std::__cxx1998::_List_const_iterator<int>; _Sequence = 
    std::__debug::list<int>; _Category = std::forward_iterator_tag; 
    __gnu_debug::_Safe_iterator<_Iterator, _Sequence, _Category>::reference 
    = const int&]

Error: attempt to dereference a singular iterator.

Objects involved in the operation:
    iterator "this" @ 0x0x7ffffb1db7f0 {
      type = std::__cxx1998::_List_const_iterator<int> (constant iterator);
      state = singular;
    }
Aborted (core dumped)


I don't think it's feasible to warn about this. As far as the compiler knows,
the iterator is just a value type. It's not practical to expect the compiler to
track that it contains a pointer to a node that is about to be destroyed by a
container going out of scope.

Reply via email to