-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA15-1-2.cpp
More file actions
61 lines (44 loc) · 918 Bytes
/
A15-1-2.cpp
File metadata and controls
61 lines (44 loc) · 918 Bytes
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
// Rule: A15-1-2
// Source line: 23442
// Original file: A15-1-2.cpp
//% $Id: A15-1-2.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <cstdint>
class A
{
// Implementation
};
void Fn(std::int16_t i)
{
A a1;
A& a2 = a1;
A* a3 = new A;
if (i < 10)
{
throw a1;
}
// Compliant - copyable object thrown
else if (i < 20)
{
throw A(); // Compliant - copyable object thrown
}
else if (i < 30)
{
throw a2; // Compliant - copyable object thrown
}
else if (i < 40)
{
throw &a1; // Non-compliant - pointer type thrown
}
else if (i < 50)
{
throw a3; // Non-compliant - pointer type thrown
}
else if (i < 60)
{
throw(*a3); // Compliant - memory leak occurs, violates other rules
}
else
{
throw new A; // Non-compliant - pointer type thrown
}
}