https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59170
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jan Kratochvil from comment #6) > (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). That doesn't help: std::vector<int>::iterator it; { std::vector<int> v{1}; it = v.begin(); } The iterator is safely initialized, safely updated to a valid value, but is not dereferenceable after the last statement. "print it" should not automatically dereference. > > 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). It works for the example above as well, and I'll make the printers do that. But most code isn't compiled with debug mode enabled.