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
This commit is contained in:
parent
005c94297d
commit
fc94bfc598
5 changed files with 61 additions and 2 deletions
|
@ -1,3 +1,14 @@
|
|||
2009-01-02 Jason Merrill <jason@redhat.com>
|
||||
|
||||
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.
|
||||
|
||||
2008-12-31 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
PR c++/38647
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2009-01-02 Jason Merrill <jason@redhat.com>
|
||||
|
||||
* g++.dg/cpp0x/initlist11.C: New test.
|
||||
* g++.dg/cpp0x/initlist12.C: New test.
|
||||
|
||||
2009-01-02 Richard Sandiford <rdsandiford@googlemail.com>
|
||||
|
||||
* gcc.dg/fixed-point/composite-type.c: Update wording of messages.
|
||||
|
|
17
gcc/testsuite/g++.dg/cpp0x/initlist11.C
Normal file
17
gcc/testsuite/g++.dg/cpp0x/initlist11.C
Normal file
|
@ -0,0 +1,17 @@
|
|||
// PR c++/38684
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
struct Y {};
|
||||
|
||||
struct X : Y {
|
||||
X(std::initializer_list<int>) {}
|
||||
};
|
||||
|
||||
struct A {
|
||||
X v;
|
||||
};
|
||||
|
||||
int main() {
|
||||
A a{ {1,2,3} };
|
||||
}
|
15
gcc/testsuite/g++.dg/cpp0x/initlist12.C
Normal file
15
gcc/testsuite/g++.dg/cpp0x/initlist12.C
Normal file
|
@ -0,0 +1,15 @@
|
|||
// PR c++/38698
|
||||
|
||||
struct A
|
||||
{
|
||||
int i;
|
||||
};
|
||||
|
||||
A a({1,2});
|
||||
|
||||
union U
|
||||
{
|
||||
int i,j;
|
||||
};
|
||||
|
||||
U u({1,2});
|
Loading…
Add table
Reference in a new issue