upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/cpp_unwind_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/test/cpp_unwind_test.cpp')
-rw-r--r--runtime/test/cpp_unwind_test.cpp31
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
3namespace {
4
5struct UnwindMarker {
6 bool& destroyed;
7 ~UnwindMarker() { destroyed = true; }
8};
9
10struct 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
20int 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}