-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA15-4-4.cpp
More file actions
108 lines (82 loc) · 1.91 KB
/
A15-4-4.cpp
File metadata and controls
108 lines (82 loc) · 1.91 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Rule: A15-4-4
// Source line: 26092
// Original file: A15-4-4.cpp
//% $Id: A15-4-4.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <iostream>
#include <stdexcept>
void F1(); // Compliant - f1, without noexcept specification, declares to throw
// exceptions implicitly
void F2() noexcept;
// Compliant - f2 does not throw exceptions
void F3() noexcept(true);
// Compliant - f3 does not throw exceptions
void F4() noexcept(false); // Compliant - f4 declares to throw exceptions
void F5() noexcept
// Compliant - f5 does not throw exceptions
{
try
{
F1(); // Exception handling needed, f1 has no noexcept specification
}
catch (std::exception& e)
{
// Handle exceptions
}
F2();
F3();
// Exception handling not needed, f2 is noexcept
// Exception handling not needed, f3 is noexcept(true)
try
{
F4();
// Exception handling needed, f4 is noexcept(false)
}
catch (std::exception& e)
{
// Handle exceptions
}
}
template <class T>
void F6() noexcept(noexcept(T()));
// Compliant - function f6() may be
// noexcept(true) or noexcept(false)
// depending on constructor of class T
template <class T>
class A
{
public:
A() noexcept(noexcept(T())) // Compliant - constructor of class A may be
// noexcept(true) or noexcept(false) depending on
// constructor of class T
{
}
};
class C1
{
public:
C1()
noexcept(
true) // Compliant - constructor of class C1 does not throw exceptions
{
}
// ...
};
class C2
{
public:
C2() // Compliant - constructor of class C2 throws exceptions
{
}
// ...
};
void F7() noexcept // Compliant - f7 does not throw exceptions
{
std::cout << noexcept(A<C1>()) << ’\n’; // prints ’1’ - constructor of
// A<C1> class is noexcept(true)
// because constructor of C1 class
// is declared to be noexcept(true)
std::cout << noexcept(A<C2>()) << ’\n’; // prints ’0’ - constructor of
// A<C2> class is noexcept(false)
// because constructor of C2 class
// has no noexcept specifier
}