https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98830
Bug ID: 98830
Summary: -Wanalyzer-null-argument on static_cast and
inheritance
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
As discussed in pr98646 comment 12, the following test case results in a likely
unintended -Wanalyzer-null-argument, possibly for the same reason as in that
bug. Since we have just suppressed this warning in the C++ front end as a
false positive it would make sense to do the same in the analyzer.
$ cat pr98646.C && gcc -S -Wall -fanalyzer -fdump-tree-gimple=/dev/stdout
pr98646.C
struct A { virtual ~A (); };
struct B { virtual ~B (); B* f (); };
struct C: A, B { virtual ~C (); void g () const; };
void f (B *p)
{
static_cast<const C*>(p->f ())->g (); // bogus
-Wanalyzer-null-argument
}
void f (struct B * p)
{
const struct C * iftmp.0;
struct B * D.2433;
D.2433 = B::f (p);
if (D.2433 != 0B) goto <D.2434>; else goto <D.2435>;
<D.2434>:
iftmp.0 = D.2433 + 18446744073709551608;
goto <D.2436>;
<D.2435>:
iftmp.0 = 0B;
<D.2436>:
C::g (iftmp.0);
}
pr98646.C: In function ‘void f(B*)’:
pr98646.C:8:37: warning: use of NULL where non-null expected [CWE-476]
[-Wanalyzer-null-argument]
8 | static_cast<const C*>(p->f ())->g (); // bogus
-Wanalyzer-null-argument
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
‘void f(B*)’: events 1-3
|
|
pr98646.C:4:38: note: argument 'this' of ‘void C::g() const’ must be non-null
4 | struct C: A, B { virtual ~C (); void g () const; };
| ^