[Bug libstdc++/105580] [13/14/15/16 Regression] warning "potential null pointer dereference" raised when using istreambuf_iterator and any "-O" flag
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Mar 2 10:28:46 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105580
--- Comment #14 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tomasz Kaminski <tkaminsk@gcc.gnu.org>:
https://gcc.gnu.org/g:bfc2b87f8244a13ab00e8e3fe2af1d6d18fcaa36
commit r16-7844-gbfc2b87f8244a13ab00e8e3fe2af1d6d18fcaa36
Author: Tomasz KamiÅski <tkaminsk@redhat.com>
Date: Fri Feb 27 20:14:44 2026 +0100
libstdc++: Add #pragma to slience null-dereference warning in
istreambuf_iterator::operator++ [PR105580]
The warning was produced by following sequence, given an
istream_iterator<char>
it, such that *it will result in hitting EoF in it->_M_get(), and thus
clearing
_M_sbuf, the subsequent call to ++it, will result in _M_sbuf->sbumpc() call
on
null pointer. This is however an false-positive, as in such situation
it == istream_iteator() returns true, and the iterator should not be
incremented in first place.
This patch sliences the issue, by disabling the "-Wnull-dereference" using
GCC diagnostic pragmas. To work correctly the pragmas needs to be placed
around
streambuf functions on which the issue originating from istreambuf_iterator
are
reported.
PR libstdc++/105580
libstdc++-v3/ChangeLog:
* include/std/streambuf (streambuf::gptr, streambuf::egptr)
(streambuf::gbump): Surround with pragma disabling
-Wnull-dereference.
* testsuite/24_iterators/istreambuf_iterator/105580.cc: Remove
check for
warning being emitted.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz KamiÅski <tkaminsk@redhat.com>
More information about the Gcc-bugs
mailing list