[Bug libstdc++/123100] std::ostringstream:str() (r-value version) returns garbage
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Dec 12 02:00:27 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123100
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
basic_stringbuf is implemented like:
```
_GLIBCXX_NODISCARD
__string_type
str() &&
{
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());
}
auto __str = std::move(_M_string);
_M_string.clear();
_M_sync(_M_string.data(), 0, 0);
return __str;
}
```
Maybe the type of __str is wrong ...
More information about the Gcc-bugs
mailing list