-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathtest.cpp
More file actions
68 lines (53 loc) · 1.06 KB
/
test.cpp
File metadata and controls
68 lines (53 loc) · 1.06 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
int i = 0;
bool f1() {
i++;
return i == 1;
}
bool f2() {
int i = 0;
return i++ == 1;
}
bool f3(int &i) {
i++;
return i == 1;
}
void f4(bool b) {
int j = 0;
if (b || i++) { // NON_COMPLIANT
}
if (b || (j == i++)) { // NON_COMPLIANT
}
if (b || f1()) { // NON_COMPLIANT, f1 has global side-effects
}
if (b || f3(j)) { // NON_COMPLIANT, f3 has local side-effects
}
}
int g1 = 0;
int f5() { return g1++; }
int f6() { return 1; }
#include <typeinfo>
void f7() {
if (1 && sizeof(f5())) {
} // COMPLIANT - sizeof operands not evaluated
if (1 &&noexcept(f5()) &&noexcept(f5())) {
} // COMPLIANT - noexcept operands not evaluated
if (1 || (typeid(f6()) == typeid(f5()))) {
} // NON_COMPLIANT - typeid operands not evaluated, but the ==operator is
}
bool f8() {
static int k = 0;
k++;
return k == 1;
}
void f9(bool b) {
if (b || f8()) { // NON_COMPLIANT, f8 has static side-effects
}
}
bool f10() {
volatile bool m = 0;
return m;
}
void f11(bool b) {
if (b || f10()) { // NON_COMPLIANT, f10 has volatile side-effects
}
}