Merge from mainline (151362:151806)
[official-gcc/graphite-test-results.git] / gcc / testsuite / c-c++-common / builtin-offsetof.c
blob6d97775467d31675dedb01c40ab5bce03d702ba5
1 // Contributed by Dodji Seketeli <dodji@redhat.com>
2 // Origin PR c++/38699
3 // { dg-options "-Warray-bounds" }
4 // { dg-do compile }
6 struct A
8 const char *p;
9 };
11 struct B
13 char p[10];
14 struct A a;
17 void
18 f0 ()
20 __builtin_offsetof(struct A, p); // OK
21 __builtin_offsetof(struct A, p[0]); // { dg-error "non constant address" }
22 __builtin_offsetof(struct B, p[0]); // OK
23 __builtin_offsetof(struct B, p[9]); // OK
24 __builtin_offsetof(struct B, p[10]); // OK
25 __builtin_offsetof(struct B, p[11]); // { dg-warning "greater than size" }
26 __builtin_offsetof(struct B, a.p); // OK
27 __builtin_offsetof(struct B, p[0]); // OK
28 __builtin_offsetof(struct B, a.p[0]); // { dg-error "non constant address" }