forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
82 lines (62 loc) · 1.84 KB
/
test.cpp
File metadata and controls
82 lines (62 loc) · 1.84 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
int may_have_side_effects();
int no_side_effects(int x) { return 1 + 2; }
int no_side_effects_nondeterministic();
int test_dead_code(int x) {
int live1 = may_have_side_effects(),
live2 = may_have_side_effects(); // COMPLIANT
int live3 = 0,
live4 = may_have_side_effects(); // COMPLIANT
int live5 = 0, live6 = 0; // COMPLIANT
live5 = 1; // COMPLIANT
live6 = 2; // COMPLIANT
int dead1 = 0, dead2 = 0; // NON_COMPLIANT
dead1 = 1; // NON_COMPLIANT - useless assignment
dead2 = 1; // NON_COMPLIANT - useless assignment
if (false) { // NON_COMPLIANT
dead2 = 10; // Only used in dead or unreachable code
}
if (true) { // COMPLIANT
may_have_side_effects();
}
if (may_have_side_effects()) { // COMPLIANT
may_have_side_effects();
}
if (true) { // NON_COMPLIANT
}
{} // NON_COMPLIANT
{ // NON_COMPLIANT
1 + 2;
}
{ // COMPLIANT
may_have_side_effects();
}
do { // COMPLIANT
may_have_side_effects();
} while (may_have_side_effects());
do { // COMPLIANT
may_have_side_effects();
} while (may_have_side_effects());
do { // NON_COMPLIANT
} while (no_side_effects_nondeterministic());
while (may_have_side_effects()) { // COMPLIANT
may_have_side_effects();
}
while (may_have_side_effects()) { // COMPLIANT
may_have_side_effects();
}
while (no_side_effects_nondeterministic()) { // NON_COMPLIANT
}
may_have_side_effects(); // COMPLIANT
1 + 2; // NON_COMPLIANT
no_side_effects(x); // NON_COMPLIANT
try { // NON_COMPLIANT
} catch (...) { // NON_COMPLIANT
}
try {
may_have_side_effects();
} catch (int i) { // COMPLIANT
} catch (...) { // NON_COMPLIANT
}
static_assert(1); // COMPLIANT
return live5 + live6; // COMPLIANT
}