diff options
author | Jason Merrill <jason@redhat.com> | 2013-07-13 19:10:24 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2013-07-13 19:10:24 -0400 |
commit | 16b53405ad2baba783cf7ecf34a623fd64db2dda (patch) | |
tree | 1dccabcb4f30ae988a32feff076c59c480009784 | |
parent | 26d40c3d4bd444bcd3dc2d44d1a405dfb8db07ec (diff) | |
download | gcc-16b53405ad2baba783cf7ecf34a623fd64db2dda.zip gcc-16b53405ad2baba783cf7ecf34a623fd64db2dda.tar.gz gcc-16b53405ad2baba783cf7ecf34a623fd64db2dda.tar.bz2 |
re PR c++/57402 (ICE: in make_decl_rtl, at varasm.c:1147 when initializing variable-sized array)
PR c++/57402
* init.c (build_vec_init): Use {} for arrays of class type.
(build_vec_delete): Don't take the address of the array.
From-SVN: r200939
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/init.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/defaulted45.C | 20 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/vla-initlist1.C | 23 |
4 files changed, 57 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1bf287a..4e46630 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2013-07-13 Jason Merrill <jason@redhat.com> + PR c++/57402 + * init.c (build_vec_init): Use {} for arrays of class type. + (build_vec_delete): Don't take the address of the array. + PR c++/57793 * class.c (layout_class_type): Check for too-large class. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 7acc7b5..808803d 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3561,10 +3561,14 @@ build_vec_init (tree base, tree maxindex, tree init, vec_free (new_vec); } - /* Clear out INIT so that we don't get confused below. */ - init = NULL_TREE; /* Any elements without explicit initializers get {}. */ - explicit_value_init_p = true; + if (cxx_dialect >= cxx11 && AGGREGATE_TYPE_P (type)) + init = build_constructor (init_list_type_node, NULL); + else + { + init = NULL_TREE; + explicit_value_init_p = true; + } } else if (from_array) { @@ -3636,11 +3640,11 @@ build_vec_init (tree base, tree maxindex, tree init, } else if (TREE_CODE (type) == ARRAY_TYPE) { - if (init != 0) + if (init && !BRACE_ENCLOSED_INITIALIZER_P (init)) sorry ("cannot initialize multi-dimensional array with initializer"); elt_init = build_vec_init (build1 (INDIRECT_REF, type, base), - 0, 0, + 0, init, explicit_value_init_p, 0, complain); } @@ -4121,7 +4125,7 @@ build_vec_delete (tree base, tree maxindex, bad name. */ maxindex = array_type_nelts_total (type); type = strip_array_types (type); - base = cp_build_addr_expr (base, complain); + base = decay_conversion (base, complain); if (base == error_mark_node) return error_mark_node; if (TREE_SIDE_EFFECTS (base)) diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted45.C b/gcc/testsuite/g++.dg/cpp0x/defaulted45.C new file mode 100644 index 0000000..e91b3a1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/defaulted45.C @@ -0,0 +1,20 @@ +// { dg-do run } +// { dg-require-effective-target c++11 } + +struct A +{ + int i; + A() = default; + A(int i): i{i} { } + ~A() {} +}; + +int main(int argc, char **argv) +{ + { int i[4] = { 42, 42, 42, 42 }; } + { + A a[4] = { argc }; + if (a[1].i != 0) + __builtin_abort (); + } +} diff --git a/gcc/testsuite/g++.dg/cpp1y/vla-initlist1.C b/gcc/testsuite/g++.dg/cpp1y/vla-initlist1.C new file mode 100644 index 0000000..1e93835 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/vla-initlist1.C @@ -0,0 +1,23 @@ +// { dg-do run } +// { dg-options "-std=c++1y" } + +#include <initializer_list> + +struct A +{ + int i; + A(std::initializer_list<int>) { } + A(int i): i{i} { } + ~A() {} +}; + +int x = 4; +int main(int argc, char **argv) +{ + { int i[x] = { 42, 42, 42, 42 }; } + { + A a[x] = { argc }; + if (a[1].i != 42) + __builtin_abort (); + } +} |