diff options
author | Jason Merrill <jason@redhat.com> | 2022-01-01 16:00:22 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-01-06 19:23:17 -0500 |
commit | beaee0a871b6485d20573fe050b1fd425581e56a (patch) | |
tree | 5b5a1320fcbead17619a0dfdfdf701528f8a5ca9 /gcc/cp/decl.c | |
parent | ce0ab8fb46f07b0bde56aa31e46d57b81379fde3 (diff) | |
download | gcc-beaee0a871b6485d20573fe050b1fd425581e56a.zip gcc-beaee0a871b6485d20573fe050b1fd425581e56a.tar.gz gcc-beaee0a871b6485d20573fe050b1fd425581e56a.tar.bz2 |
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.
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r-- | gcc/cp/decl.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9f759ce..b16a4f9 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7518,8 +7518,7 @@ initialize_local_var (tree decl, tree init) /* If we're only initializing a single object, guard the destructors of any temporaries used in its initializer with - its destructor. This isn't right for arrays because each - element initialization is a full-expression. */ + its destructor. But arrays are handled in build_vec_init. */ if (cleanup && TREE_CODE (type) != ARRAY_TYPE) wrap_temporary_cleanups (init, cleanup); |