29 lines · c
1// RUN: %check_clang_tidy %s bugprone-float-loop-counter %t2 3float g(void);4int c(float);5float f = 1.0f;6 7void match(void) {8 9 for (float x = 0.1f; x <= 1.0f; x += 0.1f) {}10 // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: loop induction expression should not have floating-point type [bugprone-float-loop-counter]11 12 for (; f > 0; --f) {}13 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression should not have floating-point type [bugprone-float-loop-counter]14 15 for (float x = 0.0f; c(x); x = g()) {}16 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: loop induction expression should not have floating-point type [bugprone-float-loop-counter]17 18 for (int i=0; i < 10 && f < 2.0f; f++, i++) {}19 // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: loop induction expression should not have floating-point type [bugprone-float-loop-counter]20 // CHECK-MESSAGES: :5:1: note: floating-point type loop induction variable21}22 23void not_match(void) {24 for (int i = 0; i < 10; i += 1.0f) {}25 for (int i = 0; i < 10; ++i) {}26 for (int i = 0; i < 10; ++i, f++) {}27 for (int i = 0; f < 10.f; ++i) {}28}29