forked from anastasiak2512/basicDemo
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCodeAnalysis.cpp
178 lines (178 loc) · 3.83 KB
/
CodeAnalysis.cpp
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//#pragma clang diagnostic push
//#pragma ide diagnostic ignored "clion-misra-cpp2008-5-3-1"
//#pragma ide diagnostic ignored "modernize-use-auto"
//#pragma ide diagnostic ignored "clion-misra-cpp2008-5-2-4"
////Check the built-in code analysis checks.
////Quick-fixes are available for many cases.
////Uncomment the file.
//
//#include <string>
//
//#include <mutex>
//
//class NeedsLock {
// std::lock_guard<std::mutex> _lock;
//
//public:
// explicit NeedsLock(std::mutex& mtx) : _lock(mtx) {}
//};
//
//int main() {
// std::mutex mtx;
// std::unique_lock lock(mtx);
// NeedsLock needs_lock(mtx);
//}
//
//void narrow_cast(int64_t p_num) {
// int32_t num = (int32_t) p_num;
// if (num == p_num) {
// //...
// }
//}
//
//void EmitVBR64(uint64_t Val, unsigned NumBits) {
// assert(NumBits <= 32 && "Too many bits to emit!");
// if ((uint32_t) Val == Val) {
// //...
// }
//}
//
//int myIntSize(const char *const str) {
// if (*str == '\0') {
// return -1; // Empty str
// }
//
// errno = 0;
//
// char *end;
// const long value = strtol(str, &end, 10);
//
// if (*end != '\0') {
// return -1; // Isn't a number
// } else if (errno == ERANGE) {
// return -1; // Overflow
// } else if (value == ((long) ((int8_t) value))) {
// return 1;
// } else if (value == ((long) ((int16_t) value))) {
// return 2;
// } else if (value == ((long) ((int32_t) value))) {
// return 4;
// } else {
// return -1; // More than 32 bit
// }
//}
//
////==========================================================
//
//void checkParam(std::string name) {
// //Press Alt+Enter for a quick-fix
//// std::string name;
//
// name.append("Test");
//}
//
////==========================================================
//
//class Ball {
//public:
// void play(int time) { /*...*/ }
//};
//class BlinkingBall : public Ball {
//public:
// //Press Alt+Enter for a quick-fix
// void play(int time) {
// //...
// }
//};
//
////==========================================================
//
//void formatSpec(int x, char * y) {
// printf("Input param: %s, %d", x, y);
//}
//
////==========================================================
//
//void eqCheck(int& a, int& b) {
// if (a = b) {
// //...
// }
//}
//
////==========================================================
//
//int * escapeScope() {
// int c = 100;
// return &c;
//}
//
////==========================================================
//
//template<typename T>
//void Foo(T, typename T::inner_type * = nullptr);
//
//template<typename T>
//decltype(T().Method()) Bar(T);
//
//struct X {
// using inner_type = void;
// static void Method() {}
//};
//
//struct Y {};
//
//void CallFooBar(X x, Y y) {
// Foo(x);
// Foo(y);
// Bar(x);
// Bar(y);
//}
//
////==========================================================
////Simplify statement
//
//template<int N>
//struct Smpl {
// static constexpr bool value = false;
//};
//template<>
//struct Smpl<0> {
// static constexpr bool value = true;
//};
//template <int N>
//void foo() {
// static constexpr bool value = Smpl<N>::value && Smpl<0>::value;
//}
////==========================================================
////Constrain a function result
//
//template<typename T>
//concept MyConcept = requires(T t){ static_cast<bool>(t); };
//
//template<class T>
//struct Strc {
// template<class U>
// MyConcept auto func() { return 2020; }
//};
//
//void test() {
// Strc<int> strc;
// auto x = strc.func<char>();
//}
//
//template<class T, class U, class V>
//concept MyComplexConcepts = true;
//
//template<class T>
//struct S3 {
// template<class U>
// MyComplexConcepts<T, U> auto func() { return 1; }
//};
//
//void test2() {
// S3<int> s3;
// auto x = s3.func<char>();
//}
//
//
//#pragma clang diagnostic pop