From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 5A43C395B44F; Fri, 13 May 2022 17:42:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A43C395B44F MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-10176] c++: array new initialized from a call [PR99643] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: 2a9658132c449e48e1c3532190c8ab72f4bbe788 X-Git-Newrev: 4231a43fd4ac6ccffd4d4b7cca70d45b2368cede Message-Id: <20220513174204.5A43C395B44F@sourceware.org> Date: Fri, 13 May 2022 17:42:04 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2022 17:42:04 -0000 https://gcc.gnu.org/g:4231a43fd4ac6ccffd4d4b7cca70d45b2368cede commit r9-10176-g4231a43fd4ac6ccffd4d4b7cca70d45b2368cede Author: Jason Merrill 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 e7e85337d76..72d2bc3121e 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1358,9 +1358,6 @@ massage_init_elt (tree type, tree init, int nested, int flags, flags &= LOOKUP_ALLOW_FLEXARRAY_INIT; flags |= LOOKUP_IMPLICIT; init = digest_init_r (type, init, nested ? 2 : 1, 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()}; +}