1// RUN: %check_clang_tidy %s bugprone-too-small-loop-variable %t -- -- --target=x86_64-linux
2
3// MagnitudeBitsUpperLimit = 16 (default value)
4
5unsigned long size() { return 294967296l; }
6
7void voidFilteredOutForLoop1() {
8 for (long i = 0; i < size(); ++i) {
9 // no warning
10 }
11}
12
13void voidCaughtForLoop1() {
14 for (int i = 0; i < size(); ++i) {
15 // no warning
16 }
17}
18
19void voidCaughtForLoop2() {
20 for (short i = 0; i < size(); ++i) {
21 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: loop variable has narrower type 'short' than iteration's upper bound 'unsigned long' [bugprone-too-small-loop-variable]
22 }
23}
24

source code of clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable-magniute-bits-upper-limit.cpp