c++: allocator temps in list of arrays [PR108773]
commite0324e2629e25a90c13c68b4eef1e47b091970c3
authorJason Merrill <jason@redhat.com>
Tue, 7 Mar 2023 03:57:57 +0000 (6 22:57 -0500)
committerJason Merrill <jason@redhat.com>
Thu, 9 Mar 2023 21:26:43 +0000 (9 16:26 -0500)
tree54d7347b1474a45b8c8a2278981c64b21feb9bec
parent4214bdb1d77ebee04d12f66c831730ed67fedf55
c++: allocator temps in list of arrays [PR108773]

The optimization to reuse the same allocator temporary for all string
constructor calls was breaking on this testcase, because the temps were
already in the argument to build_vec_init, and replacing them with
references to one slot got confused with calls at multiple levels (for the
initializer_list backing array, and then again for the array member of the
std::array).  Fixed by reusing the whole TARGET_EXPR instead of pulling out
the slot; gimplification ensures that it's only initialized once.

I also moved the check for initializing a std:: class down into the tree
walk, and handle multiple temps within a single array element
initialization.

PR c++/108773

gcc/cp/ChangeLog:

* init.cc (find_allocator_temps_r): New.
(combine_allocator_temps): Replace find_allocator_temp.
(build_vec_init): Adjust.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-array18.C: New test.
* g++.dg/cpp0x/initlist-array19.C: New test.
gcc/cp/init.cc
gcc/testsuite/g++.dg/cpp0x/initlist-array18.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/initlist-array19.C [new file with mode: 0644]