Debian Codegraph @

gcc/testsuite/g++.dg/warn/Waddress-9.C

raw
1 // PR c++/105569
2 // { dg-do compile { target c++11 } }
3 // { dg-options -Waddress }
4
5 class A {};
6
7 class B : public virtual A {};
8
9 class C : public A {};
10
11 int main() {
12 B* object = new B();
13 B &ref = *object;
14
15 bool b = nullptr == dynamic_cast<A*>(&ref); // { dg-warning "the address of 'ref' will never be NULL" }
16 bool b4 = nullptr == static_cast<A*>(&ref); // { dg-warning "the address of 'ref' will never be NULL" }
17 if (dynamic_cast<A*>(&ref)) // { dg-warning "the address of 'ref' will never be NULL" }
18 {
19 }
20 if (static_cast<A*>(&ref)) // { dg-warning "the address of 'ref' will never be NULL" }
21 {
22 }
23
24 auto ptr = dynamic_cast<A*>(&ref);
25 bool b2 = ptr == nullptr;
26
27 C* cobject = new C();
28 C &cref = *cobject;
29
30 bool b3 = nullptr == dynamic_cast<A*>(&cref);
31 }