diff options
author | Jason Merrill <jason@redhat.com> | 2021-01-15 11:42:00 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-01-15 13:38:14 -0500 |
commit | cd09079cfd50d289cbb05eadb728a0713f6bae8a (patch) | |
tree | 2b80b4b22e434bda20d942536068420b995f013c | |
parent | c0194736b477aef3cf0d15ccd12c64572869cf3f (diff) | |
download | gcc-cd09079cfd50d289cbb05eadb728a0713f6bae8a.zip gcc-cd09079cfd50d289cbb05eadb728a0713f6bae8a.tar.gz gcc-cd09079cfd50d289cbb05eadb728a0713f6bae8a.tar.bz2 |
c++: Fix list-init of array of no-copy type [PR63707]
build_vec_init_elt models initialization from some arbitrary object of the
type, i.e. copy, but in the case of list-initialization we don't do a copy
from the elements, we initialize them directly.
gcc/cp/ChangeLog:
PR c++/63707
* tree.c (build_vec_init_expr): Don't call build_vec_init_elt
if we got a CONSTRUCTOR.
gcc/testsuite/ChangeLog:
PR c++/63707
* g++.dg/cpp0x/initlist-array13.C: New test.
-rw-r--r-- | gcc/cp/tree.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/initlist-array13.C | 16 |
2 files changed, 25 insertions, 1 deletions
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 3a9a86d..290e73b 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -787,7 +787,15 @@ build_vec_init_expr (tree type, tree init, tsubst_flags_t complain) { tree slot; bool value_init = false; - tree elt_init = build_vec_init_elt (type, init, complain); + tree elt_init; + if (init && TREE_CODE (init) == CONSTRUCTOR) + { + gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (init)); + /* We built any needed constructor calls in digest_init. */ + elt_init = init; + } + else + elt_init = build_vec_init_elt (type, init, complain); if (init == void_type_node) { diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array13.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array13.C new file mode 100644 index 0000000..92fe971 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array13.C @@ -0,0 +1,16 @@ +// PR c++/63707 +// { dg-do compile { target c++11 } } + +struct Child +{ + Child (int); + ~Child (); + Child (const Child &) = delete; +}; + +struct Parent +{ + Parent () : children {{5}, {7}} {} + + Child children[2]; +}; |