https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57510
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|initializer_list memory |subobjects not destroyed |leak |when exception thrown | |during list-initialization --- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> --- Another example provided by Hubert in PR 87637: In the following program, the initialization of the A subobject of the B temporary associated with the brace-initializing cast expression is complete when an exception is thrown during the further initialization of the B temporary. When compiled with GCC, stack unwinding for the exception fails to invoke the destructor of the A subobject. ### SOURCE (<stdin>): extern "C" int printf(const char *, ...); struct A { A() { printf("%s\n", __PRETTY_FUNCTION__); } A(const A &) = delete; ~A() { printf("%s\n", __PRETTY_FUNCTION__); } }; struct B { A a; int q; }; int foo() { throw 0; } int main(void) { try { (void) B{{}, foo()}; } catch (...) { } } ### COMPILER INVOCATION: g++ -x c++ -std=c++11 -o prog - ### RUN INVOCATION: ./prog ### ACTUAL RUN OUTPUT: A::A() ### EXPECTED RUN OUTPUT: A::A() A::~A() ### COMPILER VERSION INFO (g++ -v): Using built-in specs. COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++ COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head --enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl --enable-checking=release --disable-nls --enable-lto LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32 Thread model: posix gcc version 9.0.0 20181016 (experimental) (GCC) --- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> --- *** Bug 87637 has been marked as a duplicate of this bug. ***