c++: temporary lifetime with array aggr init [PR94041]
authorJason Merrill <jason@redhat.com>
Sat, 1 Jan 2022 21:00:22 +0000 (16:00 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 7 Jan 2022 00:23:17 +0000 (19:23 -0500)
commitbeaee0a871b6485d20573fe050b1fd425581e56a
tree5b5a1320fcbead17619a0dfdfdf701528f8a5ca9
parentce0ab8fb46f07b0bde56aa31e46d57b81379fde3
c++: temporary lifetime with array aggr init [PR94041]

The previous patch fixed temporary lifetime for aggregate initialization of
classes; this one extends that fix to arrays.  This specifically reverses my
r74790, the patch for PR12253, which was made wrong when these semantics
were specified in DR201.

Since the array cleanup region encloses the regions for any temporaries, we
don't need to add an additional region for the array object itself in either
initialize_local_var or split_nonconstant_init; we do, however, need to tell
split_nonconstant_init how to disable the cleanup once an enclosing object
is fully constructed, at which point we want to run that destructor instead.

PR c++/94041

gcc/cp/ChangeLog:

* decl.c (initialize_local_var): Fix comment.
* init.c (build_new_1): Do stabilize array init.
(build_vec_init): Use TARGET_EXPR for cleanup.  Initialization
of an element from an explicit initializer is not a
full-expression.
* tree.c (expand_vec_init_expr): Pass flags through.
* typeck2.c (split_nonconstant_init_1): Handle VEC_INIT_EXPR.
(split_nonconstant_init): Handle array cleanups.
* cp-tree.h: Adjust.

gcc/testsuite/ChangeLog:

* g++.dg/init/array12.C:
* g++.dg/init/aggr7-eh2.C: New test.
* g++.dg/init/aggr7-eh3.C: New test.
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/init.c
gcc/cp/tree.c
gcc/cp/typeck2.c
gcc/testsuite/g++.dg/init/aggr7-eh2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/init/aggr7-eh3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/init/array12.C