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

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't think uncommitted mode is correct there, because stdio requires a seek
on the underlying FILE before writing to it. Setting _M_reading ensures that
will happen before the next write. Uncommitted mode would cause that seek to be
skipped.

So maybe this workaround (from comment 1) is a reasonable solution:

@@ -920,7 +925,7 @@
     {
       // Part one: update the output sequence.
       bool __testvalid = true;
-      if (this->pbase() < this->pptr())
+      if (this->pbase() < this->pptr() && __builtin_expect(!_M_reading, 1))
        {
          const int_type __tmp = this->overflow();
          if (traits_type::eq_int_type(__tmp, traits_type::eof()))

This just prevents the infinite recursion, by not trying to perform a pending
write if we're currently in read mode.

Reply via email to