2015-10-22 19:31:44 +08:00
|
|
|
// RUN: %check_clang_tidy %s modernize-loop-convert %t \
|
2015-09-25 01:02:19 +08:00
|
|
|
// RUN: -config="{CheckOptions: [{key: modernize-loop-convert.NamingStyle, value: 'UPPER_CASE'}]}" \
|
|
|
|
// RUN: -- -std=c++11 -I %S/Inputs/modernize-loop-convert
|
|
|
|
|
|
|
|
#include "structures.h"
|
|
|
|
|
|
|
|
const int N = 10;
|
|
|
|
int ARR[N];
|
|
|
|
int NUMS[N];
|
2015-10-02 21:20:11 +08:00
|
|
|
int NUMS_[N];
|
2015-09-25 01:02:19 +08:00
|
|
|
|
|
|
|
void naming() {
|
|
|
|
for (int I = 0; I < N; ++I) {
|
|
|
|
printf("%d\n", ARR[I]);
|
|
|
|
}
|
|
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
|
2015-10-22 21:23:46 +08:00
|
|
|
// CHECK-FIXES: for (int & ELEM : ARR)
|
2015-09-25 01:02:19 +08:00
|
|
|
// CHECK-FIXES-NEXT: printf("%d\n", ELEM);
|
|
|
|
|
|
|
|
for (int I = 0; I < N; ++I) {
|
|
|
|
printf("%d\n", NUMS[I]);
|
|
|
|
}
|
|
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
|
2015-10-22 21:23:46 +08:00
|
|
|
// CHECK-FIXES: for (int & NUM : NUMS)
|
2015-09-25 01:02:19 +08:00
|
|
|
// CHECK-FIXES-NEXT: printf("%d\n", NUM);
|
|
|
|
|
2015-10-02 21:20:11 +08:00
|
|
|
for (int I = 0; I < N; ++I) {
|
|
|
|
printf("%d\n", NUMS_[I]);
|
|
|
|
}
|
|
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
|
2015-10-22 21:23:46 +08:00
|
|
|
// CHECK-FIXES: for (int & NUM : NUMS_)
|
2015-10-02 21:20:11 +08:00
|
|
|
// CHECK-FIXES-NEXT: printf("%d\n", NUM);
|
|
|
|
|
2015-09-25 01:02:19 +08:00
|
|
|
int NUM = 0;
|
|
|
|
for (int I = 0; I < N; ++I) {
|
|
|
|
printf("%d\n", NUMS[I] + NUM);
|
|
|
|
}
|
|
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
|
2015-10-22 21:23:46 +08:00
|
|
|
// CHECK-FIXES: for (int & ELEM : NUMS)
|
2015-09-25 01:02:19 +08:00
|
|
|
// CHECK-FIXES-NEXT: printf("%d\n", ELEM + NUM);
|
|
|
|
|
|
|
|
int ELEM = 0;
|
|
|
|
for (int I = 0; I < N; ++I) {
|
|
|
|
printf("%d\n", NUMS[I] + NUM + ELEM);
|
|
|
|
}
|
|
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
|
2015-10-22 21:23:46 +08:00
|
|
|
// CHECK-FIXES: for (int & NUMS_I : NUMS)
|
2015-09-25 01:02:19 +08:00
|
|
|
// CHECK-FIXES-NEXT: printf("%d\n", NUMS_I + NUM + ELEM);
|
|
|
|
|
|
|
|
int NUMS_I = 0;
|
|
|
|
for (int I = 0; I < N; ++I) {
|
|
|
|
printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I);
|
|
|
|
}
|
|
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
|
2015-10-22 21:23:46 +08:00
|
|
|
// CHECK-FIXES: for (int & NUMS_ELEM : NUMS)
|
2015-09-25 01:02:19 +08:00
|
|
|
// CHECK-FIXES-NEXT: printf("%d\n", NUMS_ELEM + NUM + ELEM + NUMS_I);
|
|
|
|
|
|
|
|
int NUMS_ELEM = 0;
|
|
|
|
for (int I = 0; I < N; ++I) {
|
|
|
|
printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I + NUMS_ELEM);
|
|
|
|
}
|
|
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
|
2015-10-22 21:23:46 +08:00
|
|
|
// CHECK-FIXES: for (int & GIVE_ME_NAME_0 : NUMS)
|
2015-09-25 01:02:19 +08:00
|
|
|
// CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_0 + NUM + ELEM + NUMS_I + NUMS_ELEM);
|
|
|
|
|
|
|
|
int GIVE_ME_NAME_0 = 0;
|
|
|
|
for (int I = 0; I < N; ++I) {
|
|
|
|
printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I + NUMS_ELEM + GIVE_ME_NAME_0);
|
|
|
|
}
|
|
|
|
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
|
2015-10-22 21:23:46 +08:00
|
|
|
// CHECK-FIXES: for (int & GIVE_ME_NAME_1 : NUMS)
|
2015-09-25 01:02:19 +08:00
|
|
|
// CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_1 + NUM + ELEM + NUMS_I + NUMS_ELEM + GIVE_ME_NAME_0);
|
|
|
|
|
|
|
|
int NUMS_J = 0;
|
|
|
|
for (int I = 0; I < N; ++I) {
|
|
|
|
for (int J = 0; J < N; ++J) {
|
|
|
|
printf("%d\n", NUMS[I] + NUMS[J] + NUM + ELEM + NUMS_I + NUMS_J + NUMS_ELEM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
|
|
|
|
// CHECK-MESSAGES: :[[@LINE-5]]:5: warning: use range-based for loop instead
|
2015-10-22 21:23:46 +08:00
|
|
|
// CHECK-FIXES: for (int & GIVE_ME_NAME_0 : NUMS)
|
|
|
|
// CHECK-FIXES: for (int & GIVE_ME_NAME_1 : NUMS)
|
2015-09-25 01:02:19 +08:00
|
|
|
// CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_0 + GIVE_ME_NAME_1 + NUM + ELEM + NUMS_I + NUMS_J + NUMS_ELEM);
|
|
|
|
}
|