https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110990
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- The problem is that the _Iter_sink for contiguous iterators calls _M_overflow() to update its count of characters written, but _M_overflow() assumes it's only called when the buffer is full, and so switches to the internal buffer. The _M_finish()&& function then thinks that if the internal buffer is in use, we wrote n characters already and so returns out+n which is the end of the buffer. I'm testing a fix.