https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121924
Bug ID: 121924 Summary: exit destruction occurs with GCC for constructor that did not complete Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hstong at ca dot ibm.com Target Milestone: --- GCC generates code that calls the destructor for an object whose constructor did not complete. https://godbolt.org/z/9hPo6ahe8 ### SOURCE (<stdin>): extern "C" int printf(const char *, ...); extern "C" void exit(int); struct Temp { ~Temp() { printf("%s: %p\n", __PRETTY_FUNCTION__, (void *)this); } Temp() { static int cnt = 0; if (++cnt == 2) exit(0); printf("%s: %p\n", __PRETTY_FUNCTION__, (void *)this); } Temp(const Temp &) = delete; }; struct A { const Temp &t; }; A a[] = {Temp(), Temp()}; int main() { } ### COMPILER INVOCATION: g++ -o a.out -xc++ - ### PROGRAM INVOCATION: ./a.out ### ACTUAL OUTPUT: Temp::Temp(): 0x404040 Temp::~Temp(): 0x404041 Temp::~Temp(): 0x404040 ### EXPECTED OUTPUT: Temp::Temp(): 0x404040 Temp::~Temp(): 0x404040 ### 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/16.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 Supported LTO compression algorithms: zlib zstd gcc version 16.0.0 20250911 (experimental) (GCC)