/
unwinding_aware_destructor.cpp
54 lines (45 loc) · 1.16 KB
/
unwinding_aware_destructor.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <ostream>
#include <string>
#include <unwinding_aware_destructor.hpp>
#include "examples_common.hpp"
using namespace std;
struct DestructorInClass
{
UNWINDING_AWARE_DESTRUCTOR(DestructorInClass,unwinding)
{
cout << "DestructorInClass, unwinding: " << ( unwinding ? "true" : "false" ) << endl;
}
};
struct DestructorOutOfClass
{
UNWINDING_AWARE_DESTRUCTOR_OUF_OF_CLASS_DECL(DestructorOutOfClass,unwinding);
};
UNWINDING_AWARE_DESTRUCTOR_OUT_OF_CLASS_DEF(DestructorOutOfClass,unwinding)
{
cout << "DestructorOutOfClass, unwinding: " << ( unwinding ? "is happening" : "is not happening" ) << endl;
}
int main()
{
try
{
DestructorOutOfClass a;
DestructorInClass b;
}
catch(int) {}
try
{
DestructorOutOfClass a;
DestructorInClass b;
throw 1;
}
catch(int) {}
return 0;
}
ExpectedStdoutTest test_cout
(
"DestructorInClass, unwinding: false\n"
"DestructorOutOfClass, unwinding: is not happening\n"
"DestructorInClass, unwinding: true\n"
"DestructorOutOfClass, unwinding: is happening\n"
);