c-typeck.c (output_init_element): Allow initializing static storage duration objects with compound literals.
* c-typeck.c (output_init_element): Allow initializing static storage duration objects with compound literals. * gcc.dg/gnu89-init-1.c: Added new tests. From-SVN: r48487
This commit is contained in:
parent
d1094b40dd
commit
e6ecc89b1f
4 changed files with 32 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* 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.
|
||||
|
||||
|
@ -6275,6 +6275,16 @@ output_init_element (value, type, field, pending)
|
|||
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))
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2002-01-02 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* gcc.dg/gnu89-init-1.c: Added new tests.
|
||||
|
||||
2002-01-02 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
* g++.dg/template/friend2.C: Remove as patch is reverted.
|
||||
|
|
|
@ -8,6 +8,8 @@ extern void exit (int);
|
|||
|
||||
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
|
||||
|
@ -22,6 +24,10 @@ int c[] = (int []) { [2] = 6, 7, 8 };
|
|||
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)
|
||||
{
|
||||
|
@ -43,5 +49,11 @@ 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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue