aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Stallman <rms@gnu.org>1993-10-18 22:30:29 +0000
committerRichard Stallman <rms@gnu.org>1993-10-18 22:30:29 +0000
commit81a55c6cd52e8784b93f81b1ab22fe9cd0cb7744 (patch)
tree50c35d1a78f7b59a2b6636b618332137b4c245b5
parent733484b5d62fe6104f83bcc292caff83b0b14727 (diff)
downloadgcc-81a55c6cd52e8784b93f81b1ab22fe9cd0cb7744.zip
gcc-81a55c6cd52e8784b93f81b1ab22fe9cd0cb7744.tar.gz
gcc-81a55c6cd52e8784b93f81b1ab22fe9cd0cb7744.tar.bz2
(digest_init): If traditional, allow unbraced scalar
to initialize the first element of an aggregate. From-SVN: r5795
-rw-r--r--gcc/c-typeck.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index d201d3b..189f3bc 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -4607,6 +4607,38 @@ digest_init (type, init, require_constant, constructor_constant)
return error_mark_node;
}
+ /* Traditionally, you can write struct foo x = 0;
+ and it initializes the first element of x to 0. */
+ if (flag_traditional)
+ {
+ tree top = 0, prev = 0;
+ while (TREE_CODE (type) == RECORD_TYPE
+ || TREE_CODE (type) == ARRAY_TYPE
+ || TREE_CODE (type) == QUAL_UNION_TYPE
+ || TREE_CODE (type) == UNION_TYPE)
+ {
+ tree temp = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
+ if (prev == 0)
+ top = temp;
+ else
+ TREE_OPERAND (prev, 1) = build_tree_list (NULL_TREE, temp);
+ prev = temp;
+ if (TREE_CODE (type) == ARRAY_TYPE)
+ type = TREE_TYPE (type);
+ else if (TYPE_FIELDS (type))
+ type = TREE_TYPE (TYPE_FIELDS (type));
+ else
+ {
+ error_init ("invalid initializer%s", " for `%s'", NULL);
+ return error_mark_node;
+ }
+ }
+ TREE_OPERAND (prev, 1)
+ = build_tree_list (NULL_TREE,
+ digest_init (type, init, require_constant,
+ constructor_constant));
+ return top;
+ }
error_init ("invalid initializer%s", " for `%s'", NULL);
return error_mark_node;
}