| 1 |
/* { dg-do compile } |
| 2 |
{ dg-options "-std=c23" } */ |
| 3 |
|
| 4 |
// test that structs of variable size are detected correctly |
| 5 |
|
| 6 |
void f(int n) |
| 7 |
{ |
| 8 |
struct bar { char buf[n]; }; |
| 9 |
struct foo { struct bar y; } a; |
| 10 |
{ |
| 11 |
struct bar { char buf[n]; }; |
| 12 |
struct foo { struct bar y; } b; |
| 13 |
|
| 14 |
typeof((1 ? &a : &b)->y) c = { 0 }; /* { dg-error "variable-sized object may not be initialized" } */ |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
void g(int n) |
| 19 |
{ |
| 20 |
struct bar { char buf[n]; }; |
| 21 |
struct foo { struct bar y; } a; |
| 22 |
{ |
| 23 |
struct bar { char buf[2]; }; |
| 24 |
struct foo { struct bar y; } b; |
| 25 |
|
| 26 |
typeof((1 ? &a : &b)->y) c = { 0 }; // composite type is not of variable size |
| 27 |
} |
| 28 |
} |
| 29 |
|