https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95589
Bug ID: 95589
Summary: missing warning initializing a reference with a
dereferenced null
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
Initializing a reference by dereferenced null pointer is not diagnosed but
should be because such a reference is invalid:
$ cat t.C && gcc -O2 -S -Wall -Wextra -Wnull-dereference
-fdump-tree-optimized=/dev/stdout t.C
void f (const int&);
void g ()
{
int *p = 0;
f (*p);
}
;; Function g (_Z1gv, funcdef_no=0, decl_uid=2330, cgraph_uid=1,
symbol_order=0)
g ()
{
<bb 2> [local count: 1073741824]:
f (0B); [tail call]
return;
}
Clang doesn't diagnose it either unless --analyze is used:
$ clang -S -Wall -Wextra --analyze t.C
t.C:5:3: warning: Forming reference to null pointer
f (*p);
^~~~~~
1 warning generated.