gcc/testsuite/gcc.dg/nested-func-2.c
raw| 1 | /* PR middle-end/18820 */ |
| 2 | /* Check that we reject nested functions as initializers |
| 3 | of static variables. */ |
| 4 | |
| 5 | /* { dg-do compile } */ |
| 6 | /* { dg-options "" } */ |
| 7 | |
| 8 | struct S { |
| 9 | void (*f)(int); |
| 10 | }; |
| 11 | |
| 12 | extern void baz(struct S *); |
| 13 | extern void p(int); |
| 14 | |
| 15 | void foo(void) |
| 16 | { |
| 17 | int u; |
| 18 | |
| 19 | void bar(int val) |
| 20 | { |
| 21 | u = val; |
| 22 | } |
| 23 | |
| 24 | static struct S s = { bar }; /* { dg-error "(is not constant)|(near initialization)" } */ |
| 25 | |
| 26 | baz(&s); |
| 27 | p(u); |
| 28 | } |