[Bug c++/91777] No warning for iterator going out of scope
egallager at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Dec 23 06:13:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91777
--- Comment #8 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #7)
> 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.
Maybe not in the compiler proper; could be material for someone to write a
plugin for...
More information about the Gcc-bugs
mailing list