public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-9311] c++: Fix list-init of array of no-copy type [PR63707] Date: Fri, 29 Jan 2021 16:00:33 +0000 (GMT) [thread overview] Message-ID: <20210129160033.D09C1385481F@sourceware.org> (raw) https://gcc.gnu.org/g:81fd2df5911c4b2c31960fa5ef1407d20f1ca50c commit r10-9311-g81fd2df5911c4b2c31960fa5ef1407d20f1ca50c Author: Jason Merrill <jason@redhat.com> Date: Fri Jan 15 11:42:00 2021 -0500 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. Diff: --- gcc/cp/tree.c | 10 +++++++++- gcc/testsuite/g++.dg/cpp0x/initlist-array13.C | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 59fa0903015..59cef1770ad 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -782,7 +782,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 00000000000..92fe97164cd --- /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]; +};
reply other threads:[~2021-01-29 16:00 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210129160033.D09C1385481F@sourceware.org \ --to=jason@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).