re PR c++/38698 (ICE initializing union with initializer list)

PR c++/38698
        * typeck2.c (process_init_constructor_union): Handle union with
        no fields.

        * mangle.c (write_expression): Remove mangling for zero-operand
        casts.

From-SVN: r143111
This commit is contained in:
Jason Merrill 2009-01-05 22:27:39 -05:00 committed by Jason Merrill
parent 77d96a79bf
commit 9bfea41b05
5 changed files with 22 additions and 5 deletions

View File

@ -5,6 +5,13 @@
2009-01-05 Jason Merrill <jason@redhat.com>
PR c++/38698
* typeck2.c (process_init_constructor_union): Handle union with
no fields.
* mangle.c (write_expression): Remove mangling for zero-operand
casts.
PR c++/38701
* decl.c (cp_finish_decl): Clear DECL_INITIAL for invalid
defaulting.

View File

@ -2348,12 +2348,12 @@ write_expression (tree expr)
case CAST_EXPR:
write_type (TREE_TYPE (expr));
/* There is no way to mangle a zero-operand cast like
"T()". */
if (!TREE_OPERAND (expr, 0))
/* "T()" is mangled as "T(void)". */
write_char ('v');
sorry ("zero-operand casts cannot be mangled due to a defect "
"in the C++ ABI");
else if (list_length (TREE_OPERAND (expr, 0)) > 1)
/* FIXME the above hack for T() needs to be replaced with
something more general. */
sorry ("mangling function-style cast with more than one argument");
else
write_expression (TREE_VALUE (TREE_OPERAND (expr, 0)));

View File

@ -1147,7 +1147,11 @@ process_init_constructor_union (tree type, tree init)
tree field = TYPE_FIELDS (type);
while (field && (!DECL_NAME (field) || TREE_CODE (field) != FIELD_DECL))
field = TREE_CHAIN (field);
gcc_assert (field);
if (field == NULL_TREE)
{
error ("too many initializers for %qT", type);
ce->value = error_mark_node;
}
ce->index = field;
}

View File

@ -53,6 +53,8 @@
2009-01-05 Jason Merrill <jason@redhat.com>
* g++.dg/cpp0x/initlist12.C: Add another test.
* g++.dg/cpp0x/defaulted7.C: New test.
2009-01-05 Thomas Koenig <tkoenig@gcc.gnu.org>

View File

@ -14,3 +14,7 @@ union U
};
U u({1,2}); // { dg-error "too many initializers" }
union V {};
V v({1}); // { dg-error "too many initializers" }