public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115067] New: Bogus -O2 -Wnull-dereference for istreambuf_iterator
@ 2024-05-13 9:17 hewillk at gmail dot com
2024-05-13 11:11 ` [Bug middle-end/115067] " redi at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: hewillk at gmail dot com @ 2024-05-13 9:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115067
Bug ID: 115067
Summary: Bogus -O2 -Wnull-dereference for istreambuf_iterator
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
#include <sstream>
#include <iterator>
#include <iostream>
std::string fn() {
std::istringstream is {"bob"};
auto beg = std::istreambuf_iterator<char>(is);
auto end = std::istreambuf_iterator<char>();
return {beg, end};
}
int main() {
std::cout << fn() << "\n";
}
https://godbolt.org/z/rGqW5he87
The above code always triggers the following warning when -O2
-Wnull-dereference is used since GCC-12:
/opt/compiler-explorer/gcc-trunk-20240513/include/c++/15.0.0/streambuf:495:30:
error: potential null pointer dereference [-Werror=null-dereference]
495 | egptr() const { return _M_in_end; }
| ^~~~~~~~~
In member function 'std::basic_streambuf<_CharT, _Traits>::char_type*
std::basic_streambuf<_CharT, _Traits>::gptr() 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-trunk-20240513/include/c++/15.0.0/streambuf:326:33,
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-trunk-20240513/include/c++/15.0.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-trunk-20240513/include/c++/15.0.0/bits/basic_string.tcc:182: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-trunk-20240513/include/c++/15.0.0/bits/basic_string.h:770:16,
inlined from 'std::string fn()' at <source>:9:19:
/opt/compiler-explorer/gcc-trunk-20240513/include/c++/15.0.0/streambuf:492:30:
error: potential null pointer dereference [-Werror=null-dereference]
492 | gptr() const { return _M_in_cur; }
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug middle-end/115067] Bogus -O2 -Wnull-dereference for istreambuf_iterator
2024-05-13 9:17 [Bug c++/115067] New: Bogus -O2 -Wnull-dereference for istreambuf_iterator hewillk at gmail dot com
@ 2024-05-13 11:11 ` redi at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-13 11:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115067
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Dup
*** This bug has been marked as a duplicate of bug 105580 ***
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-13 11:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-13 9:17 [Bug c++/115067] New: Bogus -O2 -Wnull-dereference for istreambuf_iterator hewillk at gmail dot com
2024-05-13 11:11 ` [Bug middle-end/115067] " redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).