https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112421
Bug ID: 112421 Summary: GCC emits warning potential null dereference Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jlame646 at gmail dot com Target Milestone: --- GCC emits a false positive with the following code. https://godbolt.org/z/KojKWT4WK ``` std::ifstream t("file.txt"); std::string str((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>()); ``` It says: ``` In file included from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/ios:45, from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/ostream:40, from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/iostream:41, from <source>:1: In member function 'std::basic_streambuf<_CharT, _Traits>::char_type* std::basic_streambuf<_CharT, _Traits>::egptr() const [with _CharT = char; _Traits = std::char_traits<char>]', inlined from 'std::basic_streambuf<_CharT, _Traits>::int_type std::basic_streambuf<_CharT, _Traits>::sbumpc() [with _CharT = char; _Traits = std::char_traits<char>]' at /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/streambuf:326:49, inlined from 'std::istreambuf_iterator<_CharT, _Traits>& std::istreambuf_iterator<_CharT, _Traits>::operator++() [with _CharT = char; _Traits = std::char_traits<char>]' at /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/streambuf_iterator.h:173:17, inlined from 'void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_InIterator, _InIterator, std::input_iterator_tag) [with _InIterator = std::istreambuf_iterator<char, std::char_traits<char> >; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/basic_string.tcc:178:6, inlined from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(_InputIterator, _InputIterator, const _Alloc&) [with _InputIterator = std::istreambuf_iterator<char, std::char_traits<char> >; <template-parameter-2-2> = void; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' at /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/basic_string.h:753:16, inlined from 'int main()' at <source>:18:53: /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/streambuf:495:30: warning: potential null pointer dereference [-Wnull-dereference] 495 | egptr() const { return _M_in_end; } ```