diff options
| author | DanielDeGiorgio <degiorgiodaniel1808@gmail.com> | 2026-11-22 21:44:35 +0100 |
|---|---|---|
| committer | DanielDeGiorgio <degiorgiodaniel1808@gmail.com> | 2026-11-22 21:44:35 +0100 |
| commit | ddc367d0e30e84984bb8e25e9068bfe43223fadb (patch) | |
| tree | 06611cfa67a32e9ed3a985e56107226b58ac16e0 /runtime/test/cpp_unwind_test.cpp | |
| parent | f847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff) | |
Keep C++ unwinding enabled in MSVC runtime builds
Diffstat (limited to 'runtime/test/cpp_unwind_test.cpp')
| -rw-r--r-- | runtime/test/cpp_unwind_test.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
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 @@ | |||
| 1 | #include <cstdio> | ||
| 2 | |||
| 3 | namespace { | ||
| 4 | |||
| 5 | struct UnwindMarker { | ||
| 6 | bool& destroyed; | ||
| 7 | ~UnwindMarker() { destroyed = true; } | ||
| 8 | }; | ||
| 9 | |||
| 10 | struct TestException {}; | ||
| 11 | |||
| 12 | // Keep the object in a separate frame, outside the catch handler's function. | ||
| 13 | __declspec(noinline) void throw_with_marker(bool& destroyed) { | ||
| 14 | UnwindMarker marker{destroyed}; | ||
| 15 | throw TestException{}; | ||
| 16 | } | ||
| 17 | |||
| 18 | } // namespace | ||
| 19 | |||
| 20 | int main() { | ||
| 21 | bool destroyed = false; | ||
| 22 | try { | ||
| 23 | throw_with_marker(destroyed); | ||
| 24 | } catch (const TestException&) { | ||
| 25 | if (destroyed) return 0; | ||
| 26 | std::fputs("C++ exception unwound without running a destructor\n", stderr); | ||
| 27 | return 1; | ||
| 28 | } | ||
| 29 | std::fputs("Expected a C++ exception\n", stderr); | ||
| 30 | return 1; | ||
| 31 | } | ||