]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Only destruct elts of array for new expression if exception is thrown during...
authorJakub Jelinek <jakub@redhat.com>
Sat, 25 Jan 2025 09:15:24 +0000 (10:15 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 25 Jan 2025 09:15:24 +0000 (10:15 +0100)
commitce268ca2a923f8f35cc9dd5a7d0468a3980f129f
treec8247068827c7c516ad9bfb83c7b3677f13bffd1
parentd0acb7b2b26d4f821968043eafd286a1a3a37ca3
c++: Only destruct elts of array for new expression if exception is thrown during the initialization [PR117827]

The following testcase r12-6328, because the elements of the array
are destructed twice, once when the callee encounters delete[] p;
and then second time when the exception is thrown.
The array elts should be only destructed if exception is thrown from
one of the constructors during the build_vec_init emitted code in case of
new expressions, but when the new expression completes, it is IMO
responsibility of user code to delete[] it when it is no longer needed.

So, the following patch uses the cleanup_flags argument to build_vec_init
to get notified of the flags that need to be changed when the expression
is complete and build_disable_temp_cleanup to do the changes.

2025-01-25  Jakub Jelinek  <jakub@redhat.com>

PR c++/117827
* init.cc (build_new_1): Pass address of a make_tree_vector ()
initialized gc tree vector to build_vec_init and append
build_disable_temp_cleanup to init_expr from it.

* g++.dg/init/array66.C: New test.
gcc/cp/init.cc
gcc/testsuite/g++.dg/init/array66.C [new file with mode: 0644]