From 59c83dbf283e0dcf89ecfcfcbab856682291842a Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 12 Dec 2001 20:12:16 +0100 Subject: c-typeck.c (digest_init): Allow initializing static storage duration objects with compound literals. * c-typeck.c (digest_init): Allow initializing static storage duration objects with compound literals. * doc/extend.texi (Compound literals): Document the extension. * gcc.dg/gnu89-init-1.c: New test. From-SVN: r47945 --- gcc/c-typeck.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'gcc/c-typeck.c') diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 56775049a1c..f3f7d096964 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -4780,8 +4780,19 @@ digest_init (type, init, require_constant, constructor_constant) { if (code == POINTER_TYPE) inside_init = default_function_array_conversion (inside_init); - else if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST - && TREE_CODE (inside_init) != CONSTRUCTOR) + + if (require_constant && !flag_isoc99 + && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR) + { + /* 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 (inside_init); + inside_init = DECL_INITIAL (decl); + } + + if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST + && TREE_CODE (inside_init) != CONSTRUCTOR) { error_init ("array initialized from non-constant array expression"); return error_mark_node; -- cgit v1.2.1