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-9843] c++: array new initialized from a call [PR99643] Date: Thu, 20 May 2021 21:34:54 +0000 (GMT) [thread overview] Message-ID: <20210520213454.46D1D3980428@sourceware.org> (raw) https://gcc.gnu.org/g:dce71e0a274f58fe7cbabba8760f78469ba13548 commit r10-9843-gdce71e0a274f58fe7cbabba8760f78469ba13548 Author: Jason Merrill <jason@redhat.com> Date: Sat Apr 3 16:17:29 2021 -0400 c++: array new initialized from a call [PR99643] Here the get_foo() call results in a TARGET_EXPR, which we strip in massage_init_elt, but then when build_vec_init tries to use it to initialize the array element we crash because build_aggr_init expects a class rvalue to have a TARGET_EXPR. So don't strip it. The stripping was added in r206639 for PR59659, so I checked that removing it didn't significantly increase compile time or memory usage for that testcase; compile time was unaffected, memory usage increased by 0.00004%. gcc/cp/ChangeLog: PR c++/99643 * typeck2.c (massage_init_elt): Don't strip TARGET_EXPR. gcc/testsuite/ChangeLog: PR c++/99643 * g++.dg/cpp0x/initlist-new5.C: New test. Diff: --- gcc/cp/typeck2.c | 3 --- gcc/testsuite/g++.dg/cpp0x/initlist-new5.C | 9 +++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 96421caf22e..81caed45757 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1442,9 +1442,6 @@ massage_init_elt (tree type, tree init, int nested, int flags, if (flags & LOOKUP_AGGREGATE_PAREN_INIT) new_flags |= LOOKUP_AGGREGATE_PAREN_INIT; init = digest_init_r (type, init, nested ? 2 : 1, new_flags, complain); - /* Strip a simple TARGET_EXPR when we know this is an initializer. */ - if (SIMPLE_TARGET_EXPR_P (init)) - init = TARGET_EXPR_INITIAL (init); /* When we defer constant folding within a statement, we may want to defer this folding as well. */ tree t = fold_non_dependent_init (init, complain); diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-new5.C b/gcc/testsuite/g++.dg/cpp0x/initlist-new5.C new file mode 100644 index 00000000000..da54d8981d4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-new5.C @@ -0,0 +1,9 @@ +// PR c++/99643 +// { dg-do compile { target c++11 } } + +struct Foo {}; +Foo get_foo(); + +int main() { + new Foo[1]{get_foo()}; +}
reply other threads:[~2021-05-20 21:34 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=20210520213454.46D1D3980428@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).