1 // RUN: %check_clang_tidy %s readability-function-cognitive-complexity %t -- -config='{CheckOptions: [{key: readability-function-cognitive-complexity.Threshold, value: 0}]}' -- -std=c++11 -fblocks -fexceptions -w
2 
3 // any function should be checked.
4 
5 extern int ext_func(int x = 0);
6 
7 int some_func(int x = 0);
8 
some_other_func(int x=0)9 static int some_other_func(int x = 0) {}
10 
some_templ_func(T x=0)11 template<typename T> void some_templ_func(T x = 0) {}
12 
13 class SomeClass {
14 public:
15   int *begin(int x = 0);
16   int *end(int x = 0);
17   static int func(int x = 0);
some_templ_func(T x=0)18   template<typename T> void some_templ_func(T x = 0) {}
19   SomeClass() = default;
20   SomeClass(SomeClass&) = delete;
21 };
22 
23 // nothing ever decreases cognitive complexity, so we can check all the things
24 // in one go. none of the following should increase cognitive complexity:
unittest_false()25 void unittest_false() {
26   {};
27   ext_func();
28   some_func();
29   some_other_func();
30   some_templ_func<int>();
31   some_templ_func<bool>();
32   SomeClass::func();
33   SomeClass C;
34   C.some_templ_func<int>();
35   C.some_templ_func<bool>();
36   C.func();
37   C.end();
38   int i = some_func();
39   i = i;
40   i++;
41   --i;
42   i < 0;
43   int j = 0 ?: 1;
44   auto k = new int;
45   delete k;
46   throw i;
47   {
48     throw i;
49   }
50 end:
51   return;
52 }
53 
54 #if 1
55 #define CC100
56 #else
57 // this macro has cognitive complexity of 100.
58 // it is needed to be able to compare the testcases with the
59 // reference Sonar implementation. please place it right after the first
60 // CHECK-NOTES in each function
61 #define CC100 if(1){if(1){if(1){if(1){if(1){if(1){if(1){if(1){if(1){if(1){if(1){if(1){if(1){}}}}}if(1){}}}}}}}}}
62 #endif
63 
64 //----------------------------------------------------------------------------//
65 //------------------------------ B1. Increments ------------------------------//
66 //----------------------------------------------------------------------------//
67 // Check that every thing listed in B1 of the specification does indeed       //
68 // recieve the base increment, and that not-body does not increase nesting    //
69 //----------------------------------------------------------------------------//
70 
71 // break does not increase cognitive complexity.
72 // only  break LABEL  does, but it is unavaliable in C or C++
73 
74 // continue does not increase cognitive complexity.
75 // only  continue LABEL  does, but it is unavaliable in C or C++
76 
unittest_b1_00()77 void unittest_b1_00() {
78 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_00' has cognitive complexity of 33 (threshold 0) [readability-function-cognitive-complexity]
79   CC100;
80 
81   if (1 ? 1 : 0) {
82 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
83 // CHECK-NOTES: :[[@LINE-2]]:9: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
84 
85     if (1 ? 1 : 0) {
86 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
87 // CHECK-NOTES: :[[@LINE-2]]:11: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
88     } else if (1 ? 1 : 0) {
89 // CHECK-NOTES: :[[@LINE-1]]:12: note: +1, nesting level increased to 2{{$}}
90 // CHECK-NOTES: :[[@LINE-2]]:18: note: +3, including nesting penalty of 2, nesting level increased to 3{{$}}
91     } else {
92 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, nesting level increased to 2{{$}}
93     }
94   } else if (1 ? 1 : 0) {
95 // CHECK-NOTES: :[[@LINE-1]]:10: note: +1, nesting level increased to 1{{$}}
96 // CHECK-NOTES: :[[@LINE-2]]:16: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
97 
98     if (1 ? 1 : 0) {
99 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
100 // CHECK-NOTES: :[[@LINE-2]]:11: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
101     } else if (1 ? 1 : 0) {
102 // CHECK-NOTES: :[[@LINE-1]]:12: note: +1, nesting level increased to 2{{$}}
103 // CHECK-NOTES: :[[@LINE-2]]:18: note: +3, including nesting penalty of 2, nesting level increased to 3{{$}}
104     } else {
105 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, nesting level increased to 2{{$}}
106     }
107   } else {
108 // CHECK-NOTES: :[[@LINE-1]]:5: note: +1, nesting level increased to 1{{$}}
109 
110     if (1 ? 1 : 0) {
111 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
112 // CHECK-NOTES: :[[@LINE-2]]:11: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
113     } else if (1 ? 1 : 0) {
114 // CHECK-NOTES: :[[@LINE-1]]:12: note: +1, nesting level increased to 2{{$}}
115 // CHECK-NOTES: :[[@LINE-2]]:18: note: +3, including nesting penalty of 2, nesting level increased to 3{{$}}
116     } else {
117 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, nesting level increased to 2{{$}}
118     }
119   }
120 }
121 
unittest_b1_01()122 void unittest_b1_01() {
123 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_01' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
124   CC100;
125 
126   int i = (1 ? 1 : 0) ? 1 : 0;
127 // CHECK-NOTES: :[[@LINE-1]]:23: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
128 // CHECK-NOTES: :[[@LINE-2]]:14: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
129 }
130 
unittest_b1_02(int x)131 void unittest_b1_02(int x) {
132 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_02' has cognitive complexity of 9 (threshold 0) [readability-function-cognitive-complexity]
133   CC100;
134 
135   switch (1 ? 1 : 0) {
136 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
137 // CHECK-NOTES: :[[@LINE-2]]:13: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
138   case -1:
139     return;
140   case 1 ? 1 : 0:
141 // CHECK-NOTES: :[[@LINE-1]]:10: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
142     return;
143   case (1 ? 2 : 0) ... (1 ? 3 : 0):
144 // CHECK-NOTES: :[[@LINE-1]]:11: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
145 // CHECK-NOTES: :[[@LINE-2]]:27: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
146     return;
147   default:
148     break;
149   }
150 }
151 
unittest_b1_03(int x)152 void unittest_b1_03(int x) {
153 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_03' has cognitive complexity of 7 (threshold 0) [readability-function-cognitive-complexity]
154   CC100;
155 
156   for (x = 1 ? 1 : 0; x < (1 ? 1 : 0); x += 1 ? 1 : 0) {
157 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
158 // CHECK-NOTES: :[[@LINE-2]]:14: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
159 // CHECK-NOTES: :[[@LINE-3]]:30: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
160 // CHECK-NOTES: :[[@LINE-4]]:47: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
161     break;
162     continue;
163   }
164 }
165 
unittest_b1_04()166 void unittest_b1_04() {
167 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_04' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
168   CC100;
169 
170   SomeClass C;
171   for (int i : (1 ? C : C)) {
172 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
173 // CHECK-NOTES: :[[@LINE-2]]:19: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
174     break;
175     continue;
176   }
177 }
178 
unittest_b1_05()179 void unittest_b1_05() {
180 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_05' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
181   CC100;
182 
183   while (1 ? 1 : 0) {
184 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
185 // CHECK-NOTES: :[[@LINE-2]]:12: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
186     break;
187     continue;
188   }
189 }
190 
unittest_b1_06()191 void unittest_b1_06() {
192 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_06' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
193   CC100;
194 
195   do {
196 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
197     break;
198     continue;
199   } while (1 ? 1 : 0);
200 // CHECK-NOTES: :[[@LINE-1]]:14: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
201 }
202 
unittest_b1_07()203 void unittest_b1_07() {
204 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_07' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
205   CC100;
206 
207   try {
208   } catch (...) {
209 // CHECK-NOTES: :[[@LINE-1]]:5: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
210   }
211 }
212 
unittest_b1_08_00()213 void unittest_b1_08_00() {
214 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_08_00' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
215   CC100;
216 
217   goto end;
218 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1{{$}}
219 end:
220   return;
221 }
222 
unittest_b1_08_01()223 void unittest_b1_08_01() {
224 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_08_01' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
225   CC100;
226 
227   void *ptr = &&end;
228   goto *ptr;
229 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1{{$}}
230 end:
231   return;
232 }
233 
unittest_b1_09_00()234 void unittest_b1_09_00() {
235 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_09_00' has cognitive complexity of 34 (threshold 0) [readability-function-cognitive-complexity]
236   CC100;
237 
238   if(1 && 1) {
239 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
240 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
241   }
242   if(1 && 1 && 1) {
243 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
244 // CHECK-NOTES: :[[@LINE-2]]:13: note: +1{{$}}
245   }
246   if((1 && 1) && 1) {
247 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
248 // CHECK-NOTES: :[[@LINE-2]]:15: note: +1{{$}}
249   }
250   if(1 && (1 && 1)) {
251 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
252 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
253   }
254 
255   if(1 && 1 || 1) {
256 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
257 // CHECK-NOTES: :[[@LINE-2]]:13: note: +1{{$}}
258 // CHECK-NOTES: :[[@LINE-3]]:8: note: +1{{$}}
259   }
260   if((1 && 1) || 1) {
261 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
262 // CHECK-NOTES: :[[@LINE-2]]:15: note: +1{{$}}
263 // CHECK-NOTES: :[[@LINE-3]]:9: note: +1{{$}}
264   }
265   if(1 && (1 || 1)) {
266 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
267 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
268 // CHECK-NOTES: :[[@LINE-3]]:14: note: +1{{$}}
269   }
270 
271   if(1 || 1) {
272 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
273 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
274   }
275   if(1 || 1 || 1) {
276 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
277 // CHECK-NOTES: :[[@LINE-2]]:13: note: +1{{$}}
278   }
279   if((1 || 1) || 1) {
280 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
281 // CHECK-NOTES: :[[@LINE-2]]:15: note: +1{{$}}
282   }
283   if(1 || (1 || 1)) {
284 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
285 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
286   }
287 
288   if(1 || 1 && 1) {
289 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
290 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
291 // CHECK-NOTES: :[[@LINE-3]]:13: note: +1{{$}}
292   }
293   if((1 || 1) && 1) {
294 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
295 // CHECK-NOTES: :[[@LINE-2]]:15: note: +1{{$}}
296 // CHECK-NOTES: :[[@LINE-3]]:9: note: +1{{$}}
297   }
298   if(1 || (1 && 1)) {
299 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
300 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
301 // CHECK-NOTES: :[[@LINE-3]]:14: note: +1{{$}}
302   }
303 }
304 
unittest_b1_09_01()305 void unittest_b1_09_01() {
306 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_09_01' has cognitive complexity of 40 (threshold 0) [readability-function-cognitive-complexity]
307   CC100;
308 
309   if(1 && some_func(1 && 1)) {
310 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
311 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
312 // CHECK-NOTES: :[[@LINE-3]]:23: note: +1{{$}}
313   }
314   if(1 && some_func(1 || 1)) {
315 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
316 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
317 // CHECK-NOTES: :[[@LINE-3]]:23: note: +1{{$}}
318   }
319   if(1 || some_func(1 || 1)) {
320 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
321 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
322 // CHECK-NOTES: :[[@LINE-3]]:23: note: +1{{$}}
323   }
324   if(1 || some_func(1 && 1)) {
325 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
326 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
327 // CHECK-NOTES: :[[@LINE-3]]:23: note: +1{{$}}
328   }
329 
330   if(1 && some_func(1 && 1) && 1) {
331 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
332 // CHECK-NOTES: :[[@LINE-2]]:29: note: +1{{$}}
333 // CHECK-NOTES: :[[@LINE-3]]:23: note: +1{{$}}
334   }
335   if(1 && some_func(1 || 1) && 1) {
336 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
337 // CHECK-NOTES: :[[@LINE-2]]:29: note: +1{{$}}
338 // CHECK-NOTES: :[[@LINE-3]]:23: note: +1{{$}}
339   }
340   if(1 || some_func(1 || 1) && 1) {
341 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
342 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
343 // CHECK-NOTES: :[[@LINE-3]]:29: note: +1{{$}}
344 // CHECK-NOTES: :[[@LINE-4]]:23: note: +1{{$}}
345   }
346   if(1 || some_func(1 && 1) && 1) {
347 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
348 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
349 // CHECK-NOTES: :[[@LINE-3]]:29: note: +1{{$}}
350 // CHECK-NOTES: :[[@LINE-4]]:23: note: +1{{$}}
351   }
352 
353   if(1 && some_func(1 && 1) || 1) {
354 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
355 // CHECK-NOTES: :[[@LINE-2]]:29: note: +1{{$}}
356 // CHECK-NOTES: :[[@LINE-3]]:8: note: +1{{$}}
357 // CHECK-NOTES: :[[@LINE-4]]:23: note: +1{{$}}
358   }
359   if(1 && some_func(1 || 1) || 1) {
360 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
361 // CHECK-NOTES: :[[@LINE-2]]:29: note: +1{{$}}
362 // CHECK-NOTES: :[[@LINE-3]]:8: note: +1{{$}}
363 // CHECK-NOTES: :[[@LINE-4]]:23: note: +1{{$}}
364   }
365   if(1 || some_func(1 || 1) || 1) {
366 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
367 // CHECK-NOTES: :[[@LINE-2]]:29: note: +1{{$}}
368 // CHECK-NOTES: :[[@LINE-3]]:23: note: +1{{$}}
369   }
370   if(1 || some_func(1 && 1) || 1) {
371 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
372 // CHECK-NOTES: :[[@LINE-2]]:29: note: +1{{$}}
373 // CHECK-NOTES: :[[@LINE-3]]:23: note: +1{{$}}
374   }
375 }
376 
unittest_b1_09_02()377 void unittest_b1_09_02() {
378 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b1_09_02' has cognitive complexity of 12 (threshold 0) [readability-function-cognitive-complexity]
379   CC100;
380 
381   if(1 && SomeClass::func(1 && 1)) {
382 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
383 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
384 // CHECK-NOTES: :[[@LINE-3]]:29: note: +1{{$}}
385   }
386   if(1 && SomeClass::func(1 || 1)) {
387 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
388 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
389 // CHECK-NOTES: :[[@LINE-3]]:29: note: +1{{$}}
390   }
391   if(1 || SomeClass::func(1 || 1)) {
392 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
393 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
394 // CHECK-NOTES: :[[@LINE-3]]:29: note: +1{{$}}
395   }
396   if(1 || SomeClass::func(1 && 1)) {
397 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
398 // CHECK-NOTES: :[[@LINE-2]]:8: note: +1{{$}}
399 // CHECK-NOTES: :[[@LINE-3]]:29: note: +1{{$}}
400   }
401 }
402 
403 // FIXME: each method in a recursion cycle
404 
405 //----------------------------------------------------------------------------//
406 //---------------------------- B2. Nesting lebel -----------------------------//
407 //----------------------------------------------------------------------------//
408 // Check that every thing listed in B2 of the specification does indeed       //
409 // increase the nesting level                                                 //
410 //----------------------------------------------------------------------------//
411 
unittest_b2_00()412 void unittest_b2_00() {
413 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_00' has cognitive complexity of 9 (threshold 0) [readability-function-cognitive-complexity]
414   CC100;
415 
416   if (true) {
417 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
418     if(true) {
419 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
420     }
421   } else if (true) {
422 // CHECK-NOTES: :[[@LINE-1]]:10: note: +1, nesting level increased to 1{{$}}
423     if(true) {
424 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
425     }
426   } else {
427 // CHECK-NOTES: :[[@LINE-1]]:5: note: +1, nesting level increased to 1{{$}}
428     if(true) {
429 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
430     }
431   }
432 }
433 
unittest_b2_01()434 void unittest_b2_01() {
435 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_01' has cognitive complexity of 5 (threshold 0) [readability-function-cognitive-complexity]
436   CC100;
437 
438   int i = 1 ? (1 ? 1 : 0) : (1 ? 1 : 0);
439 // CHECK-NOTES: :[[@LINE-1]]:13: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
440 // CHECK-NOTES: :[[@LINE-2]]:18: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
441 // CHECK-NOTES: :[[@LINE-3]]:32: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
442 }
443 
unittest_b2_02(int x)444 void unittest_b2_02(int x) {
445 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_02' has cognitive complexity of 5 (threshold 0) [readability-function-cognitive-complexity]
446   CC100;
447 
448   switch (x) {
449 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
450   case -1:
451     if(true) {
452 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
453     }
454     return;
455   default:
456     if(true) {
457 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
458     }
459     return;
460   }
461 }
462 
unittest_b2_03()463 void unittest_b2_03() {
464 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_03' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
465   CC100;
466 
467   for (;;) {
468 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
469     if(true) {
470 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
471     }
472   }
473 }
474 
unittest_b2_04()475 void unittest_b2_04() {
476 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_04' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
477   CC100;
478 
479   SomeClass C;
480   for (int i : C) {
481 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
482     if(true) {
483 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
484     }
485   }
486 }
487 
unittest_b2_05()488 void unittest_b2_05() {
489 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_05' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
490   CC100;
491 
492   while (true) {
493 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
494     if(true) {
495 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
496     }
497   }
498 }
499 
unittest_b2_06()500 void unittest_b2_06() {
501 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_06' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
502   CC100;
503 
504   do {
505 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
506     if(true) {
507 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
508     }
509   } while (true);
510 }
511 
unittest_b2_07()512 void unittest_b2_07() {
513 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_07' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
514   CC100;
515 
516   try {
517   } catch (...) {
518 // CHECK-NOTES: :[[@LINE-1]]:5: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
519     if(true) {
520 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
521     }
522   }
523 }
524 
unittest_b2_08_00()525 void unittest_b2_08_00() {
526 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_08_00' has cognitive complexity of 10 (threshold 0) [readability-function-cognitive-complexity]
527   CC100;
528 
529   class X {
530     X() {
531 // CHECK-NOTES: :[[@LINE-1]]:5: note: nesting level increased to 1{{$}}
532       CC100;
533 
534       if (true) {
535 // CHECK-NOTES: :[[@LINE-1]]:7: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
536       }
537     }
538 
539     X &operator=(const X &other) {
540 // CHECK-NOTES: :[[@LINE-1]]:5: note: nesting level increased to 1{{$}}
541       CC100;
542 
543       if (true) {
544 // CHECK-NOTES: :[[@LINE-1]]:7: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
545       }
546     }
547 
548     ~X() {
549 // CHECK-NOTES: :[[@LINE-1]]:5: note: nesting level increased to 1{{$}}
550       CC100;
551 
552       if (true) {
553 // CHECK-NOTES: :[[@LINE-1]]:7: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
554       }
555     }
556 
557     void Y() {
558 // CHECK-NOTES: :[[@LINE-1]]:5: note: nesting level increased to 1{{$}}
559       CC100;
560 
561       if (true) {
562 // CHECK-NOTES: :[[@LINE-1]]:7: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
563       }
564     }
565 
566     static void Z() {
567 // CHECK-NOTES: :[[@LINE-1]]:5: note: nesting level increased to 1{{$}}
568       CC100;
569 
570       if (true) {
571 // CHECK-NOTES: :[[@LINE-1]]:7: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
572       }
573     }
574 
575 // CHECK-NOTES: :[[@LINE-45]]:5: warning: function 'X' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
576 // CHECK-NOTES: :[[@LINE-42]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
577 
578 // CHECK-NOTES: :[[@LINE-39]]:8: warning: function 'operator=' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
579 // CHECK-NOTES: :[[@LINE-36]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
580 
581 // CHECK-NOTES: :[[@LINE-33]]:5: warning: function '~X' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
582 // CHECK-NOTES: :[[@LINE-30]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
583 
584 // CHECK-NOTES: :[[@LINE-27]]:10: warning: function 'Y' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
585 // CHECK-NOTES: :[[@LINE-24]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
586 
587 // CHECK-NOTES: :[[@LINE-21]]:17: warning: function 'Z' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
588 // CHECK-NOTES: :[[@LINE-18]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
589   };
590 }
591 
unittest_b2_08_01()592 void unittest_b2_08_01() {
593 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_08_01' has cognitive complexity of 10 (threshold 0) [readability-function-cognitive-complexity]
594   CC100;
595 
596   struct X {
597     X() {
598 // CHECK-NOTES: :[[@LINE-1]]:5: note: nesting level increased to 1{{$}}
599       CC100;
600 
601       if (true) {
602 // CHECK-NOTES: :[[@LINE-1]]:7: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
603       }
604     }
605 
606     X &operator=(const X &other) {
607 // CHECK-NOTES: :[[@LINE-1]]:5: note: nesting level increased to 1{{$}}
608       CC100;
609 
610       if (true) {
611 // CHECK-NOTES: :[[@LINE-1]]:7: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
612       }
613     }
614 
615     ~X() {
616 // CHECK-NOTES: :[[@LINE-1]]:5: note: nesting level increased to 1{{$}}
617       CC100;
618 
619       if (true) {
620 // CHECK-NOTES: :[[@LINE-1]]:7: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
621       }
622     }
623 
624     void Y() {
625 // CHECK-NOTES: :[[@LINE-1]]:5: note: nesting level increased to 1{{$}}
626       CC100;
627 
628       if (true) {
629 // CHECK-NOTES: :[[@LINE-1]]:7: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
630       }
631     }
632 
633     static void Z() {
634 // CHECK-NOTES: :[[@LINE-1]]:5: note: nesting level increased to 1{{$}}
635       CC100;
636 
637       if (true) {
638 // CHECK-NOTES: :[[@LINE-1]]:7: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
639       }
640     }
641 
642 // CHECK-NOTES: :[[@LINE-45]]:5: warning: function 'X' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
643 // CHECK-NOTES: :[[@LINE-42]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
644 
645 // CHECK-NOTES: :[[@LINE-39]]:8: warning: function 'operator=' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
646 // CHECK-NOTES: :[[@LINE-36]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
647 
648 // CHECK-NOTES: :[[@LINE-33]]:5: warning: function '~X' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
649 // CHECK-NOTES: :[[@LINE-30]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
650 
651 // CHECK-NOTES: :[[@LINE-27]]:10: warning: function 'Y' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
652 // CHECK-NOTES: :[[@LINE-24]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
653 
654 // CHECK-NOTES: :[[@LINE-21]]:17: warning: function 'Z' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
655 // CHECK-NOTES: :[[@LINE-18]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
656   };
657 }
658 
unittest_b2_08_02()659 void unittest_b2_08_02() {
660 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_08_02' has cognitive complexity of 2 (threshold 0) [readability-function-cognitive-complexity]
661   CC100;
662 
663   auto fun = []() {
664 // CHECK-NOTES: :[[@LINE-1]]:14: note: nesting level increased to 1{{$}}
665     if (true) {
666 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
667     }
668   };
669 // CHECK-NOTES: :[[@LINE-6]]:14: warning: lambda has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
670 // CHECK-NOTES: :[[@LINE-5]]:5: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
671 }
672 
unittest_b2_09()673 void unittest_b2_09() {
674 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_09' has cognitive complexity of 2 (threshold 0) [readability-function-cognitive-complexity]
675   CC100;
676 
677   ({
678 // CHECK-NOTES: :[[@LINE-1]]:3: note: nesting level increased to 1{{$}}
679     if (true) {
680 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
681     }
682   });
683 }
684 
unittest_b2_10()685 void unittest_b2_10() {
686 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b2_10' has cognitive complexity of 2 (threshold 0) [readability-function-cognitive-complexity]
687   CC100;
688 
689   void (^foo)(void) = ^(void) {
690 // CHECK-NOTES: :[[@LINE-1]]:23: note: nesting level increased to 1{{$}}
691     if (true) {
692 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
693     }
694   };
695 }
696 
697 //----------------------------------------------------------------------------//
698 //-------------------------- B3. Nesting increments --------------------------//
699 //----------------------------------------------------------------------------//
700 // Check that every thing listed in B3 of the specification does indeed       //
701 // recieve the penalty of the current nesting level                           //
702 //----------------------------------------------------------------------------//
703 
unittest_b3_00()704 void unittest_b3_00() {
705 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b3_00' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
706   CC100;
707 
708   if (true) {
709 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
710     if (true) {
711 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
712     }
713   }
714 }
715 
unittest_b3_01()716 void unittest_b3_01() {
717 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b3_01' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
718   CC100;
719 
720   if (true) {
721 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
722     int i = 1 ? 1 : 0;
723 // CHECK-NOTES: :[[@LINE-1]]:15: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
724   }
725 }
726 
unittest_b3_02(int x)727 void unittest_b3_02(int x) {
728 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b3_02' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
729   CC100;
730 
731   if (true) {
732 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
733     switch (x) {
734 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
735     case -1:
736       return;
737     default:
738       return;
739     }
740   }
741 }
742 
unittest_b3_03()743 void unittest_b3_03() {
744 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b3_03' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
745   CC100;
746 
747   if (true) {
748 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
749     for (;;) {
750 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
751     }
752   }
753 }
754 
unittest_b3_04()755 void unittest_b3_04() {
756 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b3_04' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
757   CC100;
758 
759   if (true) {
760 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
761     SomeClass C;
762     for (int i : C) {
763 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
764     }
765   }
766 }
767 
unittest_b3_05()768 void unittest_b3_05() {
769 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b3_05' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
770   CC100;
771 
772   if (true) {
773 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
774     while (true) {
775 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
776     }
777   }
778 }
779 
unittest_b3_06()780 void unittest_b3_06() {
781 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b3_06' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
782   CC100;
783 
784   if (true) {
785 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
786     do {
787 // CHECK-NOTES: :[[@LINE-1]]:5: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
788     } while (true);
789   }
790 }
791 
unittest_b3_07()792 void unittest_b3_07() {
793 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'unittest_b3_07' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
794   CC100;
795 
796   if (true) {
797 // CHECK-NOTES: :[[@LINE-1]]:3: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
798     try {
799     } catch (...) {
800 // CHECK-NOTES: :[[@LINE-1]]:7: note: +2, including nesting penalty of 1, nesting level increased to 2{{$}}
801     }
802   }
803 }
804 
805 //----------------------------------------------------------------------------//
806 // Check that functions are being checked                                     //
807 //----------------------------------------------------------------------------//
808 
809 class CheckClass {
CheckClass(int x)810   CheckClass(int x) {
811 // CHECK-NOTES: :[[@LINE-1]]:3: warning: function 'CheckClass' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
812     CC100;
813 
814     try {
815     } catch (...) {
816 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
817     }
818   }
819 
PrivateMemberFunction()820   void PrivateMemberFunction() {
821 // CHECK-NOTES: :[[@LINE-1]]:8: warning: function 'PrivateMemberFunction' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
822     CC100;
823 
824     try {
825     } catch (...) {
826 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
827     }
828   }
829 
PrivateConstMemberFunction() const830   void PrivateConstMemberFunction() const {
831 // CHECK-NOTES: :[[@LINE-1]]:8: warning: function 'PrivateConstMemberFunction' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
832     CC100;
833 
834     try {
835     } catch (...) {
836 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
837     }
838   }
839 
PrivateStaticMemberFunction()840   static void PrivateStaticMemberFunction() {
841 // CHECK-NOTES: :[[@LINE-1]]:15: warning: function 'PrivateStaticMemberFunction' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
842     CC100;
843 
844     try {
845     } catch (...) {
846 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
847     }
848   }
849 
850 public:
CheckClass()851   CheckClass() {
852 // CHECK-NOTES: :[[@LINE-1]]:3: warning: function 'CheckClass' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
853     CC100;
854 
855     try {
856     } catch (...) {
857 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
858     }
859   }
860 
operator bool() const861   operator bool() const {
862 // CHECK-NOTES: :[[@LINE-1]]:3: warning: function 'operator bool' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
863     CC100;
864 
865     try {
866     } catch (...) {
867 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
868     }
869   }
870 
~CheckClass()871   ~CheckClass() {
872 // CHECK-NOTES: :[[@LINE-1]]:3: warning: function '~CheckClass' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
873     CC100;
874 
875     try {
876     } catch (...) {
877 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
878     }
879   }
880 
PublicMemberFunction()881   void PublicMemberFunction() {
882 // CHECK-NOTES: :[[@LINE-1]]:8: warning: function 'PublicMemberFunction' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
883     CC100;
884 
885     try {
886     } catch (...) {
887 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
888     }
889   }
890 
PublicConstMemberFunction() const891   void PublicConstMemberFunction() const {
892 // CHECK-NOTES: :[[@LINE-1]]:8: warning: function 'PublicConstMemberFunction' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
893     CC100;
894 
895     try {
896     } catch (...) {
897 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
898     }
899   }
900 
PublicStaticMemberFunction()901   static void PublicStaticMemberFunction() {
902 // CHECK-NOTES: :[[@LINE-1]]:15: warning: function 'PublicStaticMemberFunction' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
903     CC100;
904 
905     try {
906     } catch (...) {
907 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
908     }
909   }
910 
911   void PublicFunctionDefinition();
912 
913 protected:
CheckClass(bool b)914   CheckClass(bool b) {
915 // CHECK-NOTES: :[[@LINE-1]]:3: warning: function 'CheckClass' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
916     CC100;
917 
918     try {
919     } catch (...) {
920 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
921     }
922   }
923 
ProtectedMemberFunction()924   void ProtectedMemberFunction() {
925 // CHECK-NOTES: :[[@LINE-1]]:8: warning: function 'ProtectedMemberFunction' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
926     CC100;
927 
928     try {
929     } catch (...) {
930 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
931     }
932   }
933 
ProtectedConstMemberFunction() const934   void ProtectedConstMemberFunction() const {
935 // CHECK-NOTES: :[[@LINE-1]]:8: warning: function 'ProtectedConstMemberFunction' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
936     CC100;
937 
938     try {
939     } catch (...) {
940 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
941     }
942   }
943 
ProtectedStaticMemberFunction()944   static void ProtectedStaticMemberFunction() {
945 // CHECK-NOTES: :[[@LINE-1]]:15: warning: function 'ProtectedStaticMemberFunction' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
946     CC100;
947 
948     try {
949     } catch (...) {
950 // CHECK-NOTES: :[[@LINE-1]]:7: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
951     }
952   }
953 };
954 
PublicFunctionDefinition()955 void CheckClass::PublicFunctionDefinition() {
956 // CHECK-NOTES: :[[@LINE-1]]:18: warning: function 'PublicFunctionDefinition' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
957   CC100;
958 
959   try {
960   } catch (...) {
961 // CHECK-NOTES: :[[@LINE-1]]:5: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
962   }
963 }
964 
965 #define uglyfunctionmacro(name)                                                \
966   void name() {                                                                \
967     CC100;                                                                     \
968                                                                                \
969     if (true) {                                                                \
970       try {                                                                    \
971       } catch (...) {                                                          \
972       }                                                                        \
973     }                                                                          \
974   }
975 
uglyfunctionmacro(MacroFunction)976 uglyfunctionmacro(MacroFunction)
977 // CHECK-NOTES: :[[@LINE-1]]:19: warning: function 'MacroFunction' has cognitive complexity of 3 (threshold 0) [readability-function-cognitive-complexity]
978 // CHECK-NOTES: :[[@LINE-2]]:1: note: +1, including nesting penalty of 0, nesting level increased to 1
979 // CHECK-NOTES: :[[@LINE-10]]:5: note: expanded from macro 'uglyfunctionmacro'
980 // CHECK-NOTES: :[[@LINE-4]]:1: note: +2, including nesting penalty of 1, nesting level increased to 2
981 // CHECK-NOTES: :[[@LINE-10]]:9: note: expanded from macro 'uglyfunctionmacro'
982 
983 template<typename T>
984 void templatedFunction() {
985 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'templatedFunction' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
986   CC100;
987 
988   try {
989   } catch (...) {
990 // CHECK-NOTES: :[[@LINE-1]]:5: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
991   }
992 }
993 
994 template<>
templatedFunction()995 void templatedFunction<bool>() {
996 // CHECK-NOTES: :[[@LINE-1]]:6: warning: function 'templatedFunction<bool>' has cognitive complexity of 1 (threshold 0) [readability-function-cognitive-complexity]
997   CC100;
998 
999   try {
1000   } catch (...) {
1001 // CHECK-NOTES: :[[@LINE-1]]:5: note: +1, including nesting penalty of 0, nesting level increased to 1{{$}}
1002   }
1003 }
1004 
1005 template void templatedFunction<int>();
1006 
functionThatCallsTemplatedFunctions()1007 void functionThatCallsTemplatedFunctions() {
1008   templatedFunction<int>();
1009 
1010   templatedFunction<bool>();
1011 
1012   templatedFunction<char>();
1013 
1014   templatedFunction<void*>();
1015 }
1016 
1017 static void pr47779_dont_crash_on_weak() __attribute__((__weakref__("__pr47779_dont_crash_on_weak")));
1018