c++: fix array cleanup with throwing temp dtor
commitc743614e7016c5b2e5c5871cba23de68134d4950
authorJason Merrill <jason@redhat.com>
Sat, 1 Jan 2022 18:07:59 +0000 (1 13:07 -0500)
committerJason Merrill <jason@redhat.com>
Sun, 2 Jan 2022 17:56:02 +0000 (2 12:56 -0500)
tree8d82978674919f385b5f34f00cc3b7b2a732342f
parent092e60f57adeccf98e876af6b7b5734337904812
c++: fix array cleanup with throwing temp dtor

While working on PR66139 I noticed that if the destructor of a temporary
created during array initialization throws, we were failing to destroy the
last array element constructed.  Throwing destructors are rare since C++11,
but this should be fixed.

gcc/cp/ChangeLog:

* init.c (build_vec_init): Append the decrement to elt_init.

gcc/testsuite/ChangeLog:

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