aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/typeck2.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2009-01-02 19:19:55 -0500
committerJason Merrill <jason@gcc.gnu.org>2009-01-02 19:19:55 -0500
commitfc94bfc598fd5e0aacc9add9cfea4e521d329e97 (patch)
tree042912cd19fa0aedf83febd250ff3484cda11631 /gcc/cp/typeck2.c
parent005c94297dd2f123b3852cd1a1b57b604d069307 (diff)
downloadgcc-fc94bfc598fd5e0aacc9add9cfea4e521d329e97.zip
gcc-fc94bfc598fd5e0aacc9add9cfea4e521d329e97.tar.gz
gcc-fc94bfc598fd5e0aacc9add9cfea4e521d329e97.tar.bz2
re PR c++/38698 (ICE initializing union with initializer list)
PR c++/38698 * typeck2.c (process_init_constructor_union): Handle excess initializers. (process_init_constructor_record): Likewise. PR c++/38684 * typeck2.c (digest_init_r): Don't use process_init_constructor for non-aggregate classes. From-SVN: r143024
Diffstat (limited to 'gcc/cp/typeck2.c')
-rw-r--r--gcc/cp/typeck2.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 207dd99..e313e4b 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -820,7 +820,8 @@ digest_init_r (tree type, tree init, bool nested)
|| TREE_CODE (type) == UNION_TYPE
|| TREE_CODE (type) == COMPLEX_TYPE);
- if (BRACE_ENCLOSED_INITIALIZER_P (init))
+ if (BRACE_ENCLOSED_INITIALIZER_P (init)
+ && !TYPE_NON_AGGREGATE_CLASS (type))
return process_init_constructor (type, init);
else
{
@@ -1081,6 +1082,9 @@ process_init_constructor_record (tree type, tree init)
CONSTRUCTOR_APPEND_ELT (v, field, next);
}
+ if (idx < VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init)))
+ error ("too many initializers for %qT", type);
+
CONSTRUCTOR_ELTS (init) = v;
return flags;
}
@@ -1093,12 +1097,19 @@ static int
process_init_constructor_union (tree type, tree init)
{
constructor_elt *ce;
+ int len;
/* If the initializer was empty, use default zero initialization. */
if (VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (init)))
return 0;
- gcc_assert (VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init)) == 1);
+ len = VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init));
+ if (len > 1)
+ {
+ error ("too many initializers for %qT", type);
+ VEC_block_remove (constructor_elt, CONSTRUCTOR_ELTS (init), 1, len-1);
+ }
+
ce = VEC_index (constructor_elt, CONSTRUCTOR_ELTS (init), 0);
/* If this element specifies a field, initialize via that field. */