]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: initializer_list<string> and EH [PR114935]
authorJason Merrill <jason@redhat.com>
Fri, 3 May 2024 13:52:46 +0000 (09:52 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 3 May 2024 20:00:02 +0000 (16:00 -0400)
commit8f3afb83c879f1bfa722a963a07c06aaf174ef72
tree3e62425428c0384ea200388eb961bee5442097f8
parentc943d7b5c40f447b12431df9ad27a47dad95026d
c++: initializer_list<string> and EH [PR114935]

When we initialize an array of a type with a non-trivial destructor, such as
the backing array for the initializer_list, we have a cleanup to destroy any
constructed elements if a later constructor throws.  When the array being
created is a variable, the end of that EH region naturally coincides with
the beginning of the EH region for the cleanup for the variable as a whole.

But if the array is a temporary, or a subobject of one, the array cleanup
region lasts for the rest of the full-expression, along with the normal
cleanup for the TARGET_EXPR.  As a result, when tata throws we clean it up
twice.  Before r14-1705 we avoided this by disabling the array cleanup in
split_nonconstant_init, but after that we don't go through
split_nonconstant_init, so let's handle it in cp_genericize_target_expr.

PR c++/114935

gcc/cp/ChangeLog:

* cp-gimplify.cc (cp_genericize_init): Add flags parm.
(cp_genericize_init_expr): Pass nullptr.
(cp_genericize_target_expr): Handle cleanup flags.
* typeck2.cc (build_disable_temp_cleanup): Factor out of...
(split_nonconstant_init): ...here.
* cp-tree.h (build_disable_temp_cleanup): Declare.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-eh1.C: New test.
gcc/cp/cp-gimplify.cc
gcc/cp/cp-tree.h
gcc/cp/typeck2.cc
gcc/testsuite/g++.dg/cpp0x/initlist-eh1.C [new file with mode: 0644]