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.