https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124350
Bug ID: 124350
Summary: G++ on macOS produces crashing executable for nested
exception with -O0
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc at cohi dot at
Target Milestone: ---
Compiling the following code results in a crashing executable with -O0, the
executable works correctly with -O1 and -O3.
colin@maximum:/tmp/ramdisk> cat nested.cpp
#include <exception>
#include <stdexcept>
int main()
{
try {
try {
throw std::logic_error( "foo" );
}
catch( ... ) {
std::throw_with_nested( std::runtime_error( "bar" ) );
}
}
catch( const std::exception& e ) {
try {
std::rethrow_if_nested( e );
}
catch( ... ) {
return 0;
}
}
return 1;
}
colin@maximum:/tmp/ramdisk> g++-15 --version
g++-15 (Homebrew GCC 15.2.0_1) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
colin@maximum:/tmp/ramdisk> g++-15 -O0 nested.cpp
colin@maximum:/tmp/ramdisk> ./a.out
libc++abi: terminating
Abort trap: 6
colin@maximum:/tmp/ramdisk> g++-15 -O1 nested.cpp
colin@maximum:/tmp/ramdisk> ./a.out
colin@maximum:/tmp/ramdisk> echo $?
0
colin@maximum:/tmp/ramdisk> clang++ --version
Apple clang version 17.0.0 (clang-1700.6.4.2)
Target: arm64-apple-darwin25.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
colin@maximum:/tmp/ramdisk> clang++ -O0 nested.cpp
colin@maximum:/tmp/ramdisk> ./a.out
colin@maximum:/tmp/ramdisk> echo $?
0
colin@maximum:/tmp/ramdisk> clang++ -O1 nested.cpp
colin@maximum:/tmp/ramdisk> ./a.out
colin@maximum:/tmp/ramdisk> echo $?
0
colin@maximum:/tmp/ramdisk> uname -a
Darwin maximum.local 25.3.0 Darwin Kernel Version 25.3.0: Wed Jan 28 20:53:15
PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T6000 arm64
colin@maximum:/tmp/ramdisk>