1// RUN: %check_clang_tidy %s bugprone-infinite-loop %t -- -- -fblocks -fexceptions
2// RUN: %check_clang_tidy %s bugprone-infinite-loop %t -- -- -fblocks -fobjc-arc -fexceptions
3
4@interface I
5+ (void)foo;
6+ (void)bar;
7+ (void)baz __attribute__((noreturn));
8+ (instancetype)alloc;
9- (instancetype)init;
10@end
11
12_Noreturn void term();
13
14void plainCFunction() {
15 int i = 0;
16 int j = 0;
17 int a[10];
18
19 while (i < 10) {
20 // no warning, function term has C noreturn attribute
21 term();
22 }
23 while (i < 10) {
24 // no warning, class method baz has noreturn attribute
25 [I baz];
26 }
27 while (i + j < 10) {
28 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i, j) are updated in the loop body [bugprone-infinite-loop]
29 [I foo];
30 }
31 while (i + j < 10) {
32 [I foo];
33 [I baz]; // no warning, class method baz has noreturn attribute
34 }
35
36 void (^block)() = ^{
37 };
38 void __attribute__((noreturn)) (^block_nr)(void) = ^void __attribute__((noreturn)) (void) { throw "err"; };
39
40 while (i < 10) {
41 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
42 block();
43 }
44 while (i < 10) {
45 // no warning, the block has "noreturn" arribute
46 block_nr();
47 }
48}
49
50@implementation I
51+ (void)bar {
52}
53
54+ (void)foo {
55 static int i = 0;
56
57 while (i < 10) {
58 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
59 [I bar];
60 }
61}
62@end
63

source code of clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop-noreturn.mm