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

--- Comment #6 from Jan Kratochvil <jan.kratochvil at redhat dot com> ---
(In reply to Jonathan Wakely from comment #5)
> I think it's simply wrong to automatically dereference iterators. GDB
> doesn't do that when printing pointers, so why do the pretty printers do it
> for iterators?

The difference is that pointer is memory-unmanaged and this is not fixable. 
But C++ data structures have memory management (at least they should have).


> There are loads of cases where it does the wrong thing, not only for
> past-the-end iterators but also for default-constructed ones that might
> contain uninitialized pointers.

Default-constructed iterators can be detected by _M_sequence==nullptr
(-D_GLIBCXX_DEBUG).


This all depends more on a different non-pretty-printers feature I plan to file
for libstdc++ for years but I have never done so yet.  With -D_GLIBCXX_DEBUG
the iterators could be memory-managed - they already track their container by
_M_sequence.  The container could also track all its live iterators, elements
could track iterators pointing at them (and properly invalidate them upon
container updates) etc.  Deleting the container would invalidate all its
iterators etc.  Accessing an invalidated iterator would then immediately
assert.  Then it is safe to pretty print any iterator as the iterator itself
knows whether it has been invalidated or not.

Reply via email to