[Bug c++/125771] [13/14/15/16/17 Regression] Double destructor call during aggregate initialization with designated initializers when an exception is thrown.
zheng.xianyuwang at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Jun 18 22:06:28 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125771
--- Comment #2 from Wang Jinghao <zheng.xianyuwang at gmail dot com> ---
split_nonconstant_init_1() recursively generates cleanup actions, while the
outermost split_nonconstant_init() appends statements that disable those
cleanups. The generated sequence is roughly as follows:
construct a.b.c
register cleanup for a.b.c
[construct a.b]
register cleanup for a.b
throw
disable cleanup for a.b
disable cleanup for a.b.c
Therefore, on the exception path, execution never reaches the statements that
disable the cleanups. As a result, B::~B() and C::~C() are invoked in sequence,
causing the object to be destroyed twice.
More information about the Gcc-bugs
mailing list