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
108 lines (82 loc) · 1.8 KB
/
test.cpp
File metadata and controls
108 lines (82 loc) · 1.8 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
int id1;
namespace {
int id1; // NON_COMPLIANT
}
namespace ns1 {
int id1; // COMPLIANT
namespace ns2 {
int id1; // COMPLIANT
}
} // namespace ns1
class C1 {
int id1; // COMPLIANT
};
void f1() {
int id1; // NON_COMPLIANT
}
void f2(int id1) {} // NON_COMPLIANT
void f3() {
for (int id1; id1 < 1; id1++) { // NON_COMPLIANT
for (int id1; id1 < 1; id1++) {
} // NON_COMPLIANT
}
}
template <typename T> constexpr bool foo = false; // COMPLIANT
namespace {
template <typename T> bool foo = true; // COMPLIANT - omit variable templates
}
template <class T> constexpr T foo1 = T(1.1L);
template <class T, class R> T f(T r) {
T v = foo1<T> * r * r; // COMPLIANT
T v1 = foo1<R> * r * r; // COMPLIANT
}
void test_scope_order() {
{
{
int i; // COMPLIANT
}
int i; // COMPLIANT
}
for (int i = 0; i < 10; i++) { // COMPLIANT
}
try {
} catch (int i) { // COMPLIANT
}
int i; // COMPLIANT
{
{
int i; // NON_COMPLIANT
}
int i; // NON_COMPLIANT
}
for (int i = 0; i < 10; i++) { // NON_COMPLIANT
}
try {
} catch (int i) { // NON_COMPLIANT
}
}
int a;
namespace b {
int a() {} // NON_COMPLIANT
} // namespace b
namespace b1 {
typedef int a; // COMPLIANT - do not consider types
}
namespace ns_exception1_outer {
int a1; // COMPLIANT - exception
namespace ns_exception1_inner {
void a1(); // COMPLIANT - exception
}
} // namespace ns_exception1_outer
void f4() {
int a1, b;
auto lambda1 = [a1]() {
int b = 10; // COMPLIANT - exception - non captured variable b
};
auto lambda2 = [b]() {
int b = 10; // NON_COMPLIANT - not an exception - captured
// variable b
};
}
void f5(int i) {} // COMPLIANT - exception - assume purposefully overloaded
void f5(double d) {} // COMPLIANT - exception - assume purposefully overloaded