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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Ah yes, so then we might as well copy the custom buf into _M_string and then
continue as before:

--- a/libstdc++-v3/include/std/sstream
+++ b/libstdc++-v3/include/std/sstream
@@ -315,8 +315,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
       {
        if (char_type* __hi = _M_high_mark())
          {
-           // Set length to end of character sequence and add null terminator.
-           _M_string._M_set_length(_M_high_mark() - this->pbase());
+           if (_M_string.c_str() == this->pbase()) [[likely]]
+             // Set length to end of sequence and add null terminator.
+             _M_string._M_set_length(__hi - this->pbase());
+           else
+             _M_string.assign(this->pbase(), __hi);
          }
        auto __str = std::move(_M_string);
        _M_string.clear();

Reply via email to