58 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s2 3struct A {4 int a;5 struct {6 struct {7 int b;8 union {9 int c;10 };11 };12 };13};14 15int testCrash() {16 int *x = 0;17 int A::*ap = &A::a;18 19 if (ap) // no crash20 return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}21 22 return 10;23}24 25int testIndirectCrash() {26 int *x = 0;27 int A::*cp = &A::c;28 29 if (cp) // no crash30 return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}31 32 return 10;33}34 35// PR4626436// This case shall not crash with an assertion failure about void* dereferening.37namespace ns1 {38namespace a {39class b {40public:41 typedef int b::*c;42 operator c() { return d ? &b::d : 0; }43 int d;44};45} // namespace a46using a::b;47class e {48 void f();49 void g();50 b h;51};52void e::f() {53 e *i;54 if (h)55 i->g(); // expected-warning{{Called C++ object pointer is uninitialized}}56}57} // namespace ns158