summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/nested-func-2.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gcc.dg/nested-func-2.c')
-rw-r--r--gcc/testsuite/gcc.dg/nested-func-2.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/nested-func-2.c b/gcc/testsuite/gcc.dg/nested-func-2.c
new file mode 100644
index 000000000..14f14c67e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/nested-func-2.c
@@ -0,0 +1,28 @@
+/* PR middle-end/18820 */
+/* Check that we reject nested functions as initializers
+ of static variables. */
+
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct S {
+ void (*f)(int);
+};
+
+extern void baz(struct S *);
+extern void p(int);
+
+void foo(void)
+{
+ int u;
+
+ void bar(int val)
+ {
+ u = val;
+ }
+
+ static struct S s = { bar }; /* { dg-error "(is not constant)|(near initialization)" } */
+
+ baz(&s);
+ p(u);
+}