From: Jakub Jelinek Date: Wed, 2 Jan 2002 23:43:24 +0000 (+0100) Subject: c-typeck.c (output_init_element): Allow initializing static storage duration objects... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e6ecc89b1ffe1e13ba75daab525fbd29dabc6238;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cf89033c558..645b2fe4472 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2002-01-02 Jakub Jelinek + + * c-typeck.c (output_init_element): Allow initializing static storage + duration objects with compound literals. + 2002-01-02 Richard Henderson * objc/objc-act.c (hack_method_prototype): Clear current_function_decl diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 23d8a127e99..667dbe2dba1 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d225074a5b7..a4afe65ef3d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2002-01-02 Jakub Jelinek + + * gcc.dg/gnu89-init-1.c: Added new tests. + 2002-01-02 Nathan Sidwell * g++.dg/template/friend2.C: Remove as patch is reverted. diff --git a/gcc/testsuite/gcc.dg/gnu89-init-1.c b/gcc/testsuite/gcc.dg/gnu89-init-1.c index e11a0a48c2a..3cabeb443c4 100644 --- a/gcc/testsuite/gcc.dg/gnu89-init-1.c +++ b/gcc/testsuite/gcc.dg/gnu89-init-1.c @@ -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); }