]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Reject array new with -fexceptions with deleted dtor [PR123030]
authorJakub Jelinek <jakub@redhat.com>
Fri, 19 Dec 2025 09:13:45 +0000 (10:13 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 19 Dec 2025 09:13:45 +0000 (10:13 +0100)
commiteef599adc2415ebf28c4295203dfd26f92ef9420
tree0e58f041908a6bf35952d8105d7ca8c34638f7ce
parent0f5760d5992c15b94c3a395b92040fcf2a9a276a
c++: Reject array new with -fexceptions with deleted dtor [PR123030]

For array new and -fexceptions, we only try to build cleanup if
TYPE_HAS_NONTRIVIAL_DESTRUCTOR and so don't complain if the
array element has trivial but deleted destructor.

The following patch changes it to build the dtor whenever
type_build_dtor_call but only registers it as cleanup if the cleanup
has TREE_SIDE_EFFECTS.  build_vec_delete_1 has a special
case for these type_build_dtor_call && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR
cases where it does less work.

Though, I wonder if we also shouldn't test whether the ctor isn't noexcept,
then we wouldn't have to change the new4.C test.  Though, clang++ rejects
that as well even when it has noexcept ctor.

2025-12-19  Jakub Jelinek  <jakub@redhat.com>

PR c++/123030
* init.cc (build_vec_init): Call build_vec_delete_1 for -fexceptions
even if just type_build_dtor_call, not only when
TYPE_HAS_NONTRIVIAL_DESTRUCTOR.  But register cleanups only
for TYPE_HAS_NONTRIVIAL_DESTRUCTOR.

* g++.dg/cpp0x/deleted18.C: New test.
* g++.dg/cpp0x/new4.C: Expect an error.
gcc/cp/init.cc
gcc/testsuite/g++.dg/cpp0x/deleted18.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/new4.C