blob: 30cfc6ca1d17ef653723a83532049e5565dc049c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include <cstdio>
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;
}
|