+2002-01-02 Jakub Jelinek <jakub@redhat.com>
+
+ * c-typeck.c (output_init_element): Allow initializing static storage
+ duration objects with compound literals.
+
2002-01-02 Richard Henderson <rth@redhat.com>
* objc/objc-act.c (hack_method_prototype): Clear current_function_decl
/* Build expressions with type checking for C compiler.
Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
- 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of GCC.
TYPE_MAIN_VARIANT (type))))
value = default_conversion (value);
+ if (TREE_CODE (value) == COMPOUND_LITERAL_EXPR
+ && require_constant_value && !flag_isoc99 && pending)
+ {
+ /* As an extension, allow initializing objects with static storage
+ duration with compound literals (which are then treated just as
+ the brace enclosed list they contain). */
+ tree decl = COMPOUND_LITERAL_EXPR_DECL (value);
+ value = DECL_INITIAL (decl);
+ }
+
if (value == error_mark_node)
constructor_erroneous = 1;
else if (!TREE_CONSTANT (value))
struct A { int i; int j; int k[4]; };
struct B { };
+struct C { int i; };
+struct D { int i; struct C j; };
/* As a GNU extension, we allow initialization of objects with static storage
duration by compound literals. It is handled as if the object
int d[] = (int [3]) { 1 };
int e[2] = (int []) { 1, 2 };
int f[2] = (int [2]) { 1 };
+struct C g[3] = { [2] = (struct C) { 13 }, [1] = (const struct C) { 12 } };
+struct D h = { .j = (struct C) { 15 }, .i = 14 };
+struct D i[2] = { [1].j = (const struct C) { 17 },
+ [0] = { 0, (struct C) { 16 } } };
int main (void)
{
abort ();
if (sizeof (f) != 2 * sizeof (int))
abort ();
+ if (g[0].i || g[1].i != 12 || g[2].i != 13)
+ abort ();
+ if (h.i != 14 || h.j.i != 15)
+ abort ();
+ if (i[0].i || i[0].j.i != 16 || i[1].i || i[1].j.i != 17)
+ abort ();
exit (0);
}