-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA15-5-3.cpp
More file actions
92 lines (76 loc) · 1.54 KB
/
A15-5-3.cpp
File metadata and controls
92 lines (76 loc) · 1.54 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Rule: A15-5-3
// Source line: 27102
// Original file: A15-5-3.cpp
//% $Id: A15-5-3.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <stdexcept>
#include <thread>
extern bool F1();
class A
{
public:
A() noexcept(false)
{
// ...
throw std::runtime_error("Error1");
}
~A()
{
// ...
throw std::runtime_error("Error2"); // Non-compliant - std::terminate()
// called on throwing an exception
// from noexcept(true) destructor
}
};
class B
{
public:
~B() noexcept(false)
{
// ...
throw std::runtime_error("Error3");
}
};
void F2()
{
throw;
}
void ThreadFunc()
{
A a; // Throws an exception from a’s constructor and does not handle it in
// thread_func()
}
void F3()
{
try
{
std::thread t(&ThreadFunc); // Non-compliant - std::terminate() called
// on throwing an exception from
// thread_func()
if (F1())
{
throw std::logic_error("Error4");
}
else
{
F2();
// Non-compliant - std::terminate() called if there is no
// active exception to be re-thrown by f2
}
}
catch (...)
{
B b; // Non-compliant - std::terminate() called on throwing an
// exception from b’s destructor during exception handling
// ...
F2();
}
}
static A a;
// Non-compliant - std::terminate() called on throwing an exception
// during program’s start-up phase
int main(int, char**)
{
F3(); // Non-compliant - std::terminate() called if std::logic_error is
// thrown
return 0;
}