public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95473] New: GCC misses -Wnull-dereference warning in a simple code
@ 2020-06-02  5:39 haoxintu at gmail dot com
  2020-06-02  5:58 ` [Bug c++/95473] " marxin at gcc dot gnu.org
  2020-06-02 16:04 ` [Bug middle-end/95473] " msebor at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: haoxintu at gmail dot com @ 2020-06-02  5:39 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95473
           Summary: GCC misses -Wnull-dereference warning in a simple code
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

$cat null_ref.cc
int main(){
    int &x1 = *(int *)nullptr; // null reference
    return 0;
}

GCC can not catch any warning when I use -Wnull-dereference option. 
I also try to add -O1~Os, but GCC still produces nothing.

While in clang

$clang++-trunk -Wnull-dereference null_ref.cc 
null_ref.cc:2:15: warning: binding dereferenced null pointer to reference has
undefined behavior [-Wnull-dereference]
    int &x1 = *(int *)nullptr; // null reference
              ^~~~~~~~~~~~~~~
1 warning generated.

$g++ --version
g++ (GCC) 11.0.0 20200526 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

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

end of thread, other threads:[~2020-06-02 16:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02  5:39 [Bug c++/95473] New: GCC misses -Wnull-dereference warning in a simple code haoxintu at gmail dot com
2020-06-02  5:58 ` [Bug c++/95473] " marxin at gcc dot gnu.org
2020-06-02 16:04 ` [Bug middle-end/95473] " msebor 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).