summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2002-01-02 23:43:24 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2002-01-02 23:43:24 +0000
commit80dd10f324b275d7a3b4da324d2d14922c6491ef (patch)
tree45c3c1402dd4695cdcbc7dfd3f01629f6e676c30
parent42f030bd95b115c86937305e9352b6799a26cf6f (diff)
downloadgcc-80dd10f324b275d7a3b4da324d2d14922c6491ef.tar.gz
* c-typeck.c (output_init_element): Allow initializing static storage
duration objects with compound literals. * gcc.dg/gnu89-init-1.c: Added new tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@48487 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-typeck.c12
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/gnu89-init-1.c12
4 files changed, 32 insertions, 1 deletions
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 <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
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 <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.
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);
}