forked from evgeny-panasyuk/stack_unwinding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuncaught_exception_count_stress_test.cpp
More file actions
67 lines (58 loc) · 1.33 KB
/
Copy pathuncaught_exception_count_stress_test.cpp
File metadata and controls
67 lines (58 loc) · 1.33 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>
#include <boost/exception/uncaught_exception_count.hpp>
#include "examples_common.hpp"
using namespace std;
vector<unsigned> exception_counts;
const unsigned test_count=500;
struct ExpCountSaver
{
~ExpCountSaver()
{
exception_counts.push_back(boost::uncaught_exception_count());
}
};
template<int n>
struct ExptSwallower
{
~ExptSwallower()
{
try
{
ExpCountSaver p;
ExptSwallower<n-1> a;
throw 1;
suppress_unused_warning(p,a);
}catch(int){}
}
};
template<>
struct ExptSwallower<0>
{
~ExptSwallower() {}
};
int main()
{
exception_counts.reserve(test_count);
try
{
ExptSwallower<test_count> test;
suppress_unused_warning(test);
} catch(int) {}
if(exception_counts.size()!=test_count)
return 1;
adjacent_difference(exception_counts.rbegin(),exception_counts.rend(),exception_counts.rbegin());
if
(
find_if(exception_counts.begin(),exception_counts.end(), bind2nd(not_equal_to<unsigned>(),1) )
!=
exception_counts.end()
)
return 2;
return 0;
}