OSDN Git Service

2009-11-03 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / c-c++-common / dfp / builtin-offsetof.c
1 // Contributed by Dodji Seketeli <dodji@redhat.com>
2 // Origin PR c++/38699
3 // { dg-options "-Warray-bounds" }
4 // { dg-do compile }
5
6 struct A
7 {
8   const char *p;
9 };
10
11 struct B
12 {
13     char p[10];
14     struct A a;
15 };
16
17 void
18 f0 ()
19 {
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]); // { dg-warning "greater than size" }
25   __builtin_offsetof(struct B, a.p); // OK
26   __builtin_offsetof(struct B, p[0]); // OK
27   __builtin_offsetof(struct B, a.p[0]); // { dg-error "non constant address" }
28 }
29