| 1 |
// Contributed by Dodji Seketeli <[email protected]> |
| 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]); // 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" } |
| 29 |
} |