public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94867] New: New (since gcc 8) false positive with -Wnull-dereference in very simple code
@ 2020-04-30  0:25 vz-gcc at zeitlins dot org
  2020-04-30  7:16 ` [Bug c++/94867] [9 Regression] " rguenth at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: vz-gcc at zeitlins dot org @ 2020-04-30  0:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94867

            Bug ID: 94867
           Summary: New (since gcc 8) false positive with
                    -Wnull-dereference in very simple code
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vz-gcc at zeitlins dot org
  Target Milestone: ---

Consider:

% cat -n gcc-null-deref.cpp
     1  #include <vector>
     2
     3  void test()
     4  {
     5      std::vector<int> p;
     6      p.push_back(1);
     7      std::vector<int> q(p.size());
     8      q[0] = p[0];
     9  }
% g++-9 -O2 -c gcc-null-deref.cpp -Wnull-dereference
gcc-null-deref.cpp: In function ‘void test()’:
gcc-null-deref.cpp:8:10: warning: potential null pointer dereference
[-Wnull-dereference]
    8 |     q[0] = p[0];


This is with gcc version 9.3.0 (Debian 9.3.0-11). It doesn't happen with g++-8
but does still happen with the latest version available in Debian which is gcc
version 10.0.1 20200418 (experimental) [master revision
27c171775ab:4c277008be0:c5bac7d127f288fd2f8a1f15c3f30da5903141c6] (Debian
10-20200418-1)

FWIW it looks like -Wnull-dereference really doesn't like push_back() for
whatever reason. Even initializing the vector with fixed size doesn't help to
make the warning go away -- however doing this _and_ removing push_back() does
help.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-07-07  8:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-30  0:25 [Bug c++/94867] New: New (since gcc 8) false positive with -Wnull-dereference in very simple code vz-gcc at zeitlins dot org
2020-04-30  7:16 ` [Bug c++/94867] [9 Regression] " rguenth at gcc dot gnu.org
2020-04-30 18:43 ` ppalka at gcc dot gnu.org
2020-06-01 12:46 ` marxin at gcc dot gnu.org
2020-06-01 13:09 ` vz-gcc at zeitlins dot org
2020-06-01 13:53 ` marxin at gcc dot gnu.org
2020-07-24 19:18 ` ppalka at gcc dot gnu.org
2021-04-30  8:05 ` [Bug c++/94867] [9/10 " rguenth at gcc dot gnu.org
2021-06-01  8:17 ` rguenth at gcc dot gnu.org
2022-05-27  9:42 ` [Bug c++/94867] [10 " rguenth at gcc dot gnu.org
2022-06-28 10:40 ` jakub at gcc dot gnu.org
2023-07-07  8:49 ` rguenth 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).