From ddc367d0e30e84984bb8e25e9068bfe43223fadb Mon Sep 17 00:00:00 2001 From: DanielDeGiorgio Date: Sun, 22 Nov 2026 21:44:35 +0100 Subject: Keep C++ unwinding enabled in MSVC runtime builds --- runtime/test/cpp_unwind_test.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 runtime/test/cpp_unwind_test.cpp (limited to 'runtime/test/cpp_unwind_test.cpp') diff --git a/runtime/test/cpp_unwind_test.cpp b/runtime/test/cpp_unwind_test.cpp new file mode 100644 index 000000000..30cfc6ca1 --- /dev/null +++ b/runtime/test/cpp_unwind_test.cpp @@ -0,0 +1,31 @@ +#include + +namespace { + +struct UnwindMarker { + bool& destroyed; + ~UnwindMarker() { destroyed = true; } +}; + +struct TestException {}; + +// Keep the object in a separate frame, outside the catch handler's function. +__declspec(noinline) void throw_with_marker(bool& destroyed) { + UnwindMarker marker{destroyed}; + throw TestException{}; +} + +} // namespace + +int main() { + bool destroyed = false; + try { + throw_with_marker(destroyed); + } catch (const TestException&) { + if (destroyed) return 0; + std::fputs("C++ exception unwound without running a destructor\n", stderr); + return 1; + } + std::fputs("Expected a C++ exception\n", stderr); + return 1; +} -- cgit v1.2.3