| 1 |
/* testing the correct usage of flexible array members in unions |
| 2 |
and alone in structures. */ |
| 3 |
/* { dg-do run } */ |
| 4 |
/* { dg-options "-Wpedantic" } */ |
| 5 |
|
| 6 |
union with_fam_1 { |
| 7 |
int a; |
| 8 |
int b[]; /* { dg-warning "flexible array member in union is a GCC extension" } */ |
| 9 |
}; |
| 10 |
|
| 11 |
union with_fam_2 { |
| 12 |
char a; |
| 13 |
int b[]; /* { dg-warning "flexible array member in union is a GCC extension" } */ |
| 14 |
}; |
| 15 |
|
| 16 |
union with_fam_3 { |
| 17 |
char a[]; /* { dg-warning "flexible array member in union is a GCC extension" } */ |
| 18 |
/* { dg-warning "in an otherwise empty" "" { target c++ } .-1 } */ |
| 19 |
int b[]; /* { dg-warning "flexible array member in union is a GCC extension" } */ |
| 20 |
}; |
| 21 |
|
| 22 |
struct only_fam { |
| 23 |
int b[]; |
| 24 |
/* { dg-warning "in a struct with no named members" "" { target c } .-1 } */ |
| 25 |
/* { dg-warning "in an otherwise empty" "" { target c++ } .-2 } */ |
| 26 |
/* { dg-warning "forbids flexible array member" "" { target c++ } .-3 } */ |
| 27 |
}; |
| 28 |
|
| 29 |
struct only_fam_2 { |
| 30 |
unsigned int : 2; |
| 31 |
unsigned int : 3; |
| 32 |
int b[]; |
| 33 |
/* { dg-warning "in a struct with no named members" "" { target c } .-1 } */ |
| 34 |
/* { dg-warning "in an otherwise empty" "" { target c++ } .-2 } */ |
| 35 |
/* { dg-warning "forbids flexible array member" "" { target c++ } .-3 } */ |
| 36 |
}; |
| 37 |
|
| 38 |
int main () |
| 39 |
{ |
| 40 |
if (sizeof (union with_fam_1) != sizeof (int)) |
| 41 |
__builtin_abort (); |
| 42 |
if (sizeof (union with_fam_2) != __alignof__ (int)) |
| 43 |
__builtin_abort (); |
| 44 |
if (sizeof (union with_fam_3) != 0) |
| 45 |
__builtin_abort (); |
| 46 |
if (sizeof (struct only_fam) != 0) |
| 47 |
__builtin_abort (); |
| 48 |
if (sizeof (struct only_fam_2) != __alignof__ (int)) |
| 49 |
__builtin_abort (); |
| 50 |
return 0; |
| 51 |
} |
| 52 |
|