| 1 |
/* Test for -Wflex-array-member-not-at-end on structure/union with |
| 2 |
C99 flexible array members being embedded into another structure. */ |
| 3 |
/* { dg-do compile } */ |
| 4 |
/* { dg-options "-Wflex-array-member-not-at-end" } */ |
| 5 |
|
| 6 |
struct flex { int n; int data[]; }; |
| 7 |
struct out_flex_end { int m; struct flex flex_data; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 8 |
struct out_flex_mid { struct flex flex_data; int m; }; /* { dg-warning "structure containing a flexible array member is not at the end of another structure" } */ |
| 9 |
/* since the warning has been issued for out_flex_mid, no need to |
| 10 |
issue warning again when it is included in another structure/union. */ |
| 11 |
struct outer_flex_mid { struct out_flex_mid out_flex_data; int p; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 12 |
union flex_union_mid { int a; struct outer_flex_mid b; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 13 |
|
| 14 |
|
| 15 |
struct flex0 { int n; int data[0]; }; |
| 16 |
struct out_flex_end0 { int m; struct flex0 flex_data; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 17 |
struct out_flex_mid0 { struct flex0 flex_data; int m; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 18 |
struct outer_flex_mid0 { struct out_flex_mid0 out_flex_data; int p; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 19 |
union flex_union_mid0 { int a; struct outer_flex_mid0 b; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 20 |
|
| 21 |
struct flex1 { int n; int data[1]; }; |
| 22 |
struct out_flex_end1 { int m; struct flex1 flex_data; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 23 |
struct out_flex_mid1 { struct flex1 flex_data; int m; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 24 |
struct outer_flex_mid1 { struct out_flex_mid1 out_flex_data; int p; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 25 |
union flex_union_mid1 { int a; struct outer_flex_mid1 b; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 26 |
|
| 27 |
struct flexn { int n; int data[8]; }; |
| 28 |
struct out_flex_endn { int m; struct flexn flex_data; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 29 |
struct out_flex_midn { struct flexn flex_data; int m; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 30 |
struct outer_flex_midn { struct out_flex_midn out_flex_data; int p; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |
| 31 |
union flex_union_midn { int a; struct outer_flex_midn b; }; /* { dg-bogus "structure containing a flexible array member is not at the end of another structure" } */ |