1 /* PR c/102103 - missing warning comparing array address to null
3 Verify -Waddress for member arrays of structs and notes.
4 { dg-options "-Wall" } */
6 #if __cplusplus < 201103L
7 # define nullptr __null
15 int ia[]; // { dg-message "'A::ia' declared here" }
20 A a[3]; // { dg-message "'B::a' declared here" }
25 B b[3]; // { dg-message "'C::b' declared here" }
30 C c[3]; // { dg-message "'D::c' declared here" }
34 void test_waddress_1d ()
36 D d[2]; // { dg-message "'d' declared here" }
38 T (d); // { dg-warning "address of 'd'" }
39 T (d == nullptr); // { dg-warning "address of 'd'" }
40 T (&d); // { dg-warning "address of 'd'" }
41 T (d->c); // { dg-warning "address of 'D::c'" }
42 T (d->c != nullptr); // { dg-warning "address of 'D::c'" }
43 T (d->c->b); // { dg-warning "address of 'C::b'" }
44 T (d->c[1].b->a); // { dg-warning "address of 'B::a'" }
45 T (d->c->b[2].a->ia); // { dg-warning "address of 'A::ia'" }
47 if (d->c->b[2].a[1].ia) // { dg-warning "address of 'A::ia'" }
50 if (bool b = d->c->b[1].a) // { dg-warning "address of 'B::a'" }
53 /* The following is represented as a declaration of P followed
54 by an if statement and so it isn't diagnosed. It's not clear
55 that it should be since the pointer is then used.
56 void *p = d->c->b[2].a;
59 if (void *p = d->c->b[2].a) // { dg-warning "address of 'A::ia'" "" { xfail *-*-* } }
64 void test_waddress_2d (int i)
66 D d[2][3]; // { dg-message "'d' declared here" }
68 T (d); // { dg-warning "address of 'd'" }
69 T (d == nullptr); // { dg-warning "address of 'd'" }
70 T (&d); // { dg-warning "address of 'd'" }
71 T (*d); // { dg-warning "address of 'd'" }
72 T (d[1] != nullptr); // { dg-warning "address of 'd'" }
73 T (&d[1]->c); // { dg-warning "address of 'D::c'" }
74 T (d[1]->c); // { dg-warning "address of 'D::c'" }
75 T (d[1]->c == nullptr); // { dg-warning "address of 'D::c'" }
76 T (d[i]->c[1].b); // { dg-warning "address of 'C::b'" }
77 T ((*(d + i))->c->b->a); // { dg-warning "address of 'B::a'" }
78 T (d[1][2].c->b->a->ia); // { dg-warning "address of 'A::ia'" }