Libstdc++ Fixes Potential Null-Dereference in istreambuf_iterator
Libstdc++ now avoids a potential null-dereference warning in `istreambuf_iterator` by adjusting how the internal stream buffer pointer is handled.
Libstdc++ now clears the internal stream buffer pointer (_M_sbuf) in istreambuf_iterator::operator++() instead of _M_get(). This change addresses a false-positive null-dereference warning that could occur when incrementing an iterator that had previously reached the end of the stream. This also allows removing mutable from _M_sbuf, improving conformance with the C++11 standard regarding data races.
In Details
This commit resolves PR105580 by modifying istreambuf_iterator to avoid a null-dereference warning. The fix involves clearing _M_sbuf in operator++() instead of _M_get(), which eliminates the need for _M_sbuf to be mutable. This change impacts post-increment behavior (*it++) by calling both sgetc() and snextc(), in contrast to the previous single sbumpc() call.
For Context
An istreambuf_iterator is an input iterator that reads characters from a stream buffer. A stream buffer handles the low-level details of reading from and writing to a stream. This commit fixes a potential null-dereference warning in libstdc++'s istreambuf_iterator by changing where the internal stream buffer pointer is cleared. This change ensures that the iterator behaves correctly when reaching the end of a stream, and adheres to data race standards.