GLIBCXX_DEBUG bug in list::merge?

David Greene
Sat Apr 19 17:05:00 GMT 2008

David Greene wrote:
> The code below triggers what I think is a bogus assert in GLIBCXX_DEBUG
> mode.  According to iterators
> remain valid after a merge operation.  I don't have a copy of the
> standard.  Does it say the same?
> If so, I believe list::merge needs to update the _M_sequence members of
> the safe iterators merged into the list.
> I've filed bug 35969.

Knowing that the SGI docs are very old, I looked at the 1998 draft
standard at:

According to this document, a splice invalidates iterators for the
elements being spliced.  So according to that document the testcase is
invalid and GLIBCXX_DEBUG mode should cause an assert at the second 
splice due to an invalid iterator being passed to it.  But it does not.

Perhaps this was changed in the final standard.  I don't have access to
that document.  It surprises me that splice and merge would invalidate
iterators since a prime motivator for using std::list is iterator
stability and these two operations don't destroy any sequence values,
they just move them around.

No books on the standard library that I've found address iterator
stability for std::list splice and merge operations, which leads
the reader to assume that iterators remain valid.


More information about the Gcc-help mailing list