1 // RUN: %check_clang_tidy %s bugprone-terminating-continue %t
2 
f()3 void f() {
4   do {
5     continue;
6     // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'continue' in loop with false condition is equivalent to 'break' [bugprone-terminating-continue]
7     // CHECK-FIXES: break;
8   } while(false);
9 
10   do {
11     continue;
12     // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'continue' in loop with false condition is equivalent to 'break' [bugprone-terminating-continue]
13     // CHECK-FIXES: break;
14   } while(0);
15 
16   do {
17     continue;
18     // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'continue' in loop with false condition is equivalent to 'break' [bugprone-terminating-continue]
19     // CHECK-FIXES: break;
20   } while(nullptr);
21 
22   do {
23     continue;
24     // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'continue' in loop with false condition is equivalent to 'break' [bugprone-terminating-continue]
25     // CHECK-FIXES: break;
26   } while(__null);
27 
28 
29   do {
30     int x = 1;
31     if (x > 0) continue;
32     // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'continue' in loop with false condition is equivalent to 'break' [bugprone-terminating-continue]
33     // CHECK-FIXES: if (x > 0) break;
34   } while (false);
35 
36   switch (2) {
37   case 2:
38     do {
39       continue; // LoopInSwitch
40       // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'continue' in loop with false condition is equivalent to 'break' [bugprone-terminating-continue]
41       // CHECK-FIXES: break; // LoopInSwitch
42     } while (0);
43   }
44 }
45 
g()46 void g() {
47   do {
48     do {
49       continue;
50       int x = 1;
51     } while (1 == 1);
52   } while (false);
53 
54   do {
55     for (int i = 0; i < 1; ++i) {
56       continue;
57       int x = 1;
58     }
59   } while (false);
60 
61   do {
62     while (true) {
63       continue;
64       int x = 1;
65     }
66   } while (false);
67 
68   int v[] = {1,2,3,34};
69   do {
70     for (int n : v) {
71       if (n>2) continue;
72     }
73   } while (false);
74 
75   do {
76     switch (2) {
77     case 1:
78     case 2:
79       continue;
80     }
81   } while (false);
82 }
83