diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-03-26 19:51:58 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-03-26 19:51:58 +0000 |
commit | 4102f6177fa94f8782745e4e4363f171517ea399 (patch) | |
tree | 4621d4112107ceb1f4cb50bd5eaee486ea48ada4 | |
parent | 72b0dfe12228baef053adb954dbb7f6d66830e59 (diff) | |
download | gcc-4102f6177fa94f8782745e4e4363f171517ea399.tar.gz |
PR c++/65154
* init.c (build_vec_init): Fix initializing aggregates
with empty init list.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@221704 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/init.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/init/array39.C | 46 |
3 files changed, 53 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e3699f63c04..684129b2200 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-03-26 Mikhail Maltsev <maltsevm@gmail.com> + + PR c++/65154 + * init.c (build_vec_init): Fix initializing aggregates + with empty init list. + 2015-03-26 Jason Merrill <jason@redhat.com> PR c++/65525 diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 0274663c8f4..957a7a4e6e8 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3716,11 +3716,7 @@ build_vec_init (tree base, tree maxindex, tree init, { if (cxx_dialect >= cxx11 && AGGREGATE_TYPE_P (type)) { - if (BRACE_ENCLOSED_INITIALIZER_P (init) - && CONSTRUCTOR_NELTS (init) == 0) - /* Reuse it. */; - else - init = build_constructor (init_list_type_node, NULL); + init = build_constructor (init_list_type_node, NULL); CONSTRUCTOR_IS_DIRECT_INIT (init) = true; } else diff --git a/gcc/testsuite/g++.dg/init/array39.C b/gcc/testsuite/g++.dg/init/array39.C new file mode 100644 index 00000000000..2fd89377162 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/array39.C @@ -0,0 +1,46 @@ +// PR c++/65154 +// { dg-do run { target c++11 } } + +int cnt1 = 0, + cnt2 = 0; + +struct S_empty +{ + S_empty () { + cnt1++; + }; +}; + +struct C1 +{ + S_empty s; +}; + +struct S_init +{ + S_init () : i(42) + { + cnt2++; + }; + int i; +}; + +struct C2 +{ + S_init a, b; +}; + +int +main () +{ + C1 c1[5]{}; + C2 c2[1]{}; + + if (c2[0].a.i != 42 || c2[0].b.i != 42) + return 1; + + if (cnt1 != 5 || cnt2 != 2) + return 1; + + return 0; +} |