Commit 9bfea41b by Jason Merrill Committed by Jason Merrill

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
parent 77d96a79
...@@ -5,6 +5,13 @@ ...@@ -5,6 +5,13 @@
2009-01-05 Jason Merrill <jason@redhat.com> 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 PR c++/38701
* decl.c (cp_finish_decl): Clear DECL_INITIAL for invalid * decl.c (cp_finish_decl): Clear DECL_INITIAL for invalid
defaulting. defaulting.
......
...@@ -2348,12 +2348,12 @@ write_expression (tree expr) ...@@ -2348,12 +2348,12 @@ write_expression (tree expr)
case CAST_EXPR: case CAST_EXPR:
write_type (TREE_TYPE (expr)); write_type (TREE_TYPE (expr));
/* There is no way to mangle a zero-operand cast like
"T()". */
if (!TREE_OPERAND (expr, 0)) if (!TREE_OPERAND (expr, 0))
/* "T()" is mangled as "T(void)". */ sorry ("zero-operand casts cannot be mangled due to a defect "
write_char ('v'); "in the C++ ABI");
else if (list_length (TREE_OPERAND (expr, 0)) > 1) 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"); sorry ("mangling function-style cast with more than one argument");
else else
write_expression (TREE_VALUE (TREE_OPERAND (expr, 0))); write_expression (TREE_VALUE (TREE_OPERAND (expr, 0)));
......
...@@ -1147,7 +1147,11 @@ process_init_constructor_union (tree type, tree init) ...@@ -1147,7 +1147,11 @@ process_init_constructor_union (tree type, tree init)
tree field = TYPE_FIELDS (type); tree field = TYPE_FIELDS (type);
while (field && (!DECL_NAME (field) || TREE_CODE (field) != FIELD_DECL)) while (field && (!DECL_NAME (field) || TREE_CODE (field) != FIELD_DECL))
field = TREE_CHAIN (field); 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; ce->index = field;
} }
......
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
2009-01-05 Jason Merrill <jason@redhat.com> 2009-01-05 Jason Merrill <jason@redhat.com>
* g++.dg/cpp0x/initlist12.C: Add another test.
* g++.dg/cpp0x/defaulted7.C: New test. * g++.dg/cpp0x/defaulted7.C: New test.
2009-01-05 Thomas Koenig <tkoenig@gcc.gnu.org> 2009-01-05 Thomas Koenig <tkoenig@gcc.gnu.org>
......
...@@ -14,3 +14,7 @@ union U ...@@ -14,3 +14,7 @@ union U
}; };
U u({1,2}); // { dg-error "too many initializers" } U u({1,2}); // { dg-error "too many initializers" }
union V {};
V v({1}); // { dg-error "too many initializers" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment