1 | // RUN: %check_clang_tidy %s cert-flp30-c %t |
2 | |
3 | float g(void); |
4 | int c(float); |
5 | float f = 1.0f; |
6 | |
7 | void 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 [cert-flp30-c] |
11 | |
12 | for (; f > 0; --f) {} |
13 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: loop induction expression should not have floating-point type [cert-flp30-c] |
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 [cert-flp30-c] |
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 [cert-flp30-c] |
20 | // CHECK-MESSAGES: :5:1: note: floating-point type loop induction variable |
21 | } |
22 | |
23 | void 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 | |