Use the old index identifier by default, instead of 'elem'.

Summary: Use the old index name in the cases where the check would come up with an invented name.

Reviewers: klimek

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D14438

llvm-svn: 252308
This commit is contained in:
Angel Garcia Gomez 2015-11-06 15:03:14 +00:00
parent 73d1044abe
commit 7056f7488f
7 changed files with 304 additions and 484 deletions

View File

@ -831,54 +831,7 @@ std::string VariableNamer::createIndexName() {
return IteratorName; return IteratorName;
} }
std::string Elem; return OldIndex->getName();
switch (Style) {
case NS_CamelBack:
case NS_LowerCase:
Elem = "elem";
break;
case NS_CamelCase:
Elem = "Elem";
break;
case NS_UpperCase:
Elem = "ELEM";
}
// E.g.: (auto elem : container)
if (!declarationExists(Elem))
return Elem;
IteratorName = AppendWithStyle(ContainerName, OldIndex->getName());
// E.g.: (auto container_i : container)
if (!declarationExists(IteratorName) || IteratorName == OldIndex->getName())
return IteratorName;
IteratorName = AppendWithStyle(ContainerName, Elem);
// E.g.: (auto container_elem : container)
if (!declarationExists(IteratorName) || IteratorName == OldIndex->getName())
return IteratorName;
// Someone defeated my naming scheme...
std::string GiveMeName;
switch (Style) {
case NS_CamelBack:
GiveMeName = "giveMeName";
break;
case NS_CamelCase:
GiveMeName = "GiveMeName";
break;
case NS_LowerCase:
GiveMeName = "give_me_name_";
break;
case NS_UpperCase:
GiveMeName = "GIVE_ME_NAME_";
}
int Attempt = 0;
do {
IteratorName = GiveMeName + std::to_string(Attempt++);
} while (declarationExists(IteratorName) ||
IteratorName == OldIndex->getName());
return IteratorName;
} }
/// \brief Determines whether or not the the name \a Symbol conflicts with /// \brief Determines whether or not the the name \a Symbol conflicts with

View File

@ -18,8 +18,8 @@ void f() {
int K; int K;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead [modernize-loop-convert] // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead [modernize-loop-convert]
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: Sum += Elem; // CHECK-FIXES-NEXT: Sum += I;
// CHECK-FIXES-NEXT: int K; // CHECK-FIXES-NEXT: int K;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
@ -27,66 +27,66 @@ void f() {
Sum += Arr[I] + 2; Sum += Arr[I] + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
// CHECK-FIXES-NEXT: Sum += Elem + 2; // CHECK-FIXES-NEXT: Sum += I + 2;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
int X = Arr[I]; int X = Arr[I];
int Y = Arr[I] + 2; int Y = Arr[I] + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: int X = Elem; // CHECK-FIXES-NEXT: int X = I;
// CHECK-FIXES-NEXT: int Y = Elem + 2; // CHECK-FIXES-NEXT: int Y = I + 2;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
int X = N; int X = N;
X = Arr[I]; X = Arr[I];
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: int X = N; // CHECK-FIXES-NEXT: int X = N;
// CHECK-FIXES-NEXT: X = Elem; // CHECK-FIXES-NEXT: X = I;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
Arr[I] += 1; Arr[I] += 1;
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES: for (int & I : Arr)
// CHECK-FIXES-NEXT: Elem += 1; // CHECK-FIXES-NEXT: I += 1;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
int X = Arr[I] + 2; int X = Arr[I] + 2;
Arr[I]++; Arr[I]++;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES: for (int & I : Arr)
// CHECK-FIXES-NEXT: int X = Elem + 2; // CHECK-FIXES-NEXT: int X = I + 2;
// CHECK-FIXES-NEXT: Elem++; // CHECK-FIXES-NEXT: I++;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
Arr[I] = 4 + Arr[I]; Arr[I] = 4 + Arr[I];
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES: for (int & I : Arr)
// CHECK-FIXES-NEXT: Elem = 4 + Elem; // CHECK-FIXES-NEXT: I = 4 + I;
for (int I = 0; I < NMinusOne + 1; ++I) { for (int I = 0; I < NMinusOne + 1; ++I) {
Sum += Arr[I]; Sum += Arr[I];
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: Sum += Elem; // CHECK-FIXES-NEXT: Sum += I;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
printf("Fibonacci number %d has address %p\n", Arr[I], &Arr[I]); printf("Fibonacci number %d has address %p\n", Arr[I], &Arr[I]);
Sum += Arr[I] + 2; Sum += Arr[I] + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES: for (int & I : Arr)
// CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", Elem, &Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, &I);
// CHECK-FIXES-NEXT: Sum += Elem + 2; // CHECK-FIXES-NEXT: Sum += I + 2;
Val Teas[N]; Val Teas[N];
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
@ -102,24 +102,24 @@ const int *constArray() {
printf("2 * %d = %d\n", ConstArr[I], ConstArr[I] + ConstArr[I]); printf("2 * %d = %d\n", ConstArr[I], ConstArr[I] + ConstArr[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : ConstArr) // CHECK-FIXES: for (int I : ConstArr)
// CHECK-FIXES-NEXT: printf("2 * %d = %d\n", Elem, Elem + Elem); // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I, I + I);
const NonTriviallyCopyable NonCopy[N]{}; const NonTriviallyCopyable NonCopy[N]{};
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
printf("2 * %d = %d\n", NonCopy[I].X, NonCopy[I].X + NonCopy[I].X); printf("2 * %d = %d\n", NonCopy[I].X, NonCopy[I].X + NonCopy[I].X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (const auto & Elem : NonCopy) // CHECK-FIXES: for (const auto & I : NonCopy)
// CHECK-FIXES-NEXT: printf("2 * %d = %d\n", Elem.X, Elem.X + Elem.X); // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
const TriviallyCopyableButBig Big[N]{}; const TriviallyCopyableButBig Big[N]{};
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
printf("2 * %d = %d\n", Big[I].X, Big[I].X + Big[I].X); printf("2 * %d = %d\n", Big[I].X, Big[I].X + Big[I].X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (const auto & Elem : Big) // CHECK-FIXES: for (const auto & I : Big)
// CHECK-FIXES-NEXT: printf("2 * %d = %d\n", Elem.X, Elem.X + Elem.X); // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X);
bool Something = false; bool Something = false;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
@ -127,9 +127,9 @@ const int *constArray() {
return &ConstArr[I]; return &ConstArr[I];
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (const int & Elem : ConstArr) // CHECK-FIXES: for (const int & I : ConstArr)
// CHECK-FIXES-NEXT: if (Something) // CHECK-FIXES-NEXT: if (Something)
// CHECK-FIXES-NEXT: return &Elem; // CHECK-FIXES-NEXT: return &I;
} }
struct HasArr { struct HasArr {
@ -140,15 +140,15 @@ struct HasArr {
printf("%d", Arr[I]); printf("%d", Arr[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: printf("%d", Elem); // CHECK-FIXES-NEXT: printf("%d", I);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
printf("%d", ValArr[I].X); printf("%d", ValArr[I].X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : ValArr) // CHECK-FIXES: for (auto & I : ValArr)
// CHECK-FIXES-NEXT: printf("%d", Elem.X); // CHECK-FIXES-NEXT: printf("%d", I.X);
} }
void explicitThis() { void explicitThis() {
@ -156,15 +156,15 @@ struct HasArr {
printf("%d", this->Arr[I]); printf("%d", this->Arr[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : this->Arr) // CHECK-FIXES: for (int I : this->Arr)
// CHECK-FIXES-NEXT: printf("%d", Elem); // CHECK-FIXES-NEXT: printf("%d", I);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
printf("%d", this->ValArr[I].X); printf("%d", this->ValArr[I].X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : this->ValArr) // CHECK-FIXES: for (auto & I : this->ValArr)
// CHECK-FIXES-NEXT: printf("%d", Elem.X); // CHECK-FIXES-NEXT: printf("%d", I.X);
} }
}; };
@ -175,15 +175,15 @@ struct HasIndirectArr {
printf("%d", HA.Arr[I]); printf("%d", HA.Arr[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : HA.Arr) // CHECK-FIXES: for (int I : HA.Arr)
// CHECK-FIXES-NEXT: printf("%d", Elem); // CHECK-FIXES-NEXT: printf("%d", I);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
printf("%d", HA.ValArr[I].X); printf("%d", HA.ValArr[I].X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : HA.ValArr) // CHECK-FIXES: for (auto & I : HA.ValArr)
// CHECK-FIXES-NEXT: printf("%d", Elem.X); // CHECK-FIXES-NEXT: printf("%d", I.X);
} }
void explicitThis() { void explicitThis() {
@ -191,15 +191,15 @@ struct HasIndirectArr {
printf("%d", this->HA.Arr[I]); printf("%d", this->HA.Arr[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : this->HA.Arr) // CHECK-FIXES: for (int I : this->HA.Arr)
// CHECK-FIXES-NEXT: printf("%d", Elem); // CHECK-FIXES-NEXT: printf("%d", I);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
printf("%d", this->HA.ValArr[I].X); printf("%d", this->HA.ValArr[I].X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : this->HA.ValArr) // CHECK-FIXES: for (auto & I : this->HA.ValArr)
// CHECK-FIXES-NEXT: printf("%d", Elem.X); // CHECK-FIXES-NEXT: printf("%d", I.X);
} }
}; };
@ -217,8 +217,8 @@ void memberFunctionPointer() {
for (int I = 0; I < N; ++I) for (int I = 0; I < N; ++I)
(V.*mfpArr[I])(); (V.*mfpArr[I])();
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : mfpArr) // CHECK-FIXES: for (auto & I : mfpArr)
// CHECK-FIXES-NEXT: (V.*Elem)(); // CHECK-FIXES-NEXT: (V.*I)();
struct Foo { struct Foo {
int (Val::*f)(); int (Val::*f)();
@ -227,8 +227,8 @@ void memberFunctionPointer() {
for (int I = 0; I < N; ++I) for (int I = 0; I < N; ++I)
int R = (V.*(Foo[I].f))(); int R = (V.*(Foo[I].f))();
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Foo) // CHECK-FIXES: for (auto & I : Foo)
// CHECK-FIXES-NEXT: int R = (V.*(Elem.f))(); // CHECK-FIXES-NEXT: int R = (V.*(I.f))();
} }
@ -243,24 +243,24 @@ void f() {
printf("I found %d\n", *It); printf("I found %d\n", *It);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Tt) // CHECK-FIXES: for (int & It : Tt)
// CHECK-FIXES-NEXT: printf("I found %d\n", Elem); // CHECK-FIXES-NEXT: printf("I found %d\n", It);
T *Pt; T *Pt;
for (T::iterator It = Pt->begin(), E = Pt->end(); It != E; ++It) { for (T::iterator It = Pt->begin(), E = Pt->end(); It != E; ++It) {
printf("I found %d\n", *It); printf("I found %d\n", *It);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : *Pt) // CHECK-FIXES: for (int & It : *Pt)
// CHECK-FIXES-NEXT: printf("I found %d\n", Elem); // CHECK-FIXES-NEXT: printf("I found %d\n", It);
S Ss; S Ss;
for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) { for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) {
printf("s has value %d\n", (*It).X); printf("s has value %d\n", (*It).X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Ss) // CHECK-FIXES: for (auto & It : Ss)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
S *Ps; S *Ps;
for (S::iterator It = Ps->begin(), E = Ps->end(); It != E; ++It) { for (S::iterator It = Ps->begin(), E = Ps->end(); It != E; ++It) {
@ -274,58 +274,58 @@ void f() {
printf("s has value %d\n", (*It).X); printf("s has value %d\n", (*It).X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto Elem : Ss) // CHECK-FIXES: for (auto It : Ss)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) { for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) {
printf("s has value %d\n", It->X); printf("s has value %d\n", It->X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Ss) // CHECK-FIXES: for (auto & It : Ss)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) { for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) {
It->X = 3; It->X = 3;
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Ss) // CHECK-FIXES: for (auto & It : Ss)
// CHECK-FIXES-NEXT: Elem.X = 3; // CHECK-FIXES-NEXT: It.X = 3;
for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) { for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) {
(*It).X = 3; (*It).X = 3;
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Ss) // CHECK-FIXES: for (auto & It : Ss)
// CHECK-FIXES-NEXT: Elem.X = 3; // CHECK-FIXES-NEXT: It.X = 3;
for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) { for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) {
It->nonConstFun(4, 5); It->nonConstFun(4, 5);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Ss) // CHECK-FIXES: for (auto & It : Ss)
// CHECK-FIXES-NEXT: Elem.nonConstFun(4, 5); // CHECK-FIXES-NEXT: It.nonConstFun(4, 5);
U Uu; U Uu;
for (U::iterator It = Uu.begin(), E = Uu.end(); It != E; ++It) { for (U::iterator It = Uu.begin(), E = Uu.end(); It != E; ++It) {
printf("s has value %d\n", It->X); printf("s has value %d\n", It->X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Uu) // CHECK-FIXES: for (auto & It : Uu)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
for (U::iterator It = Uu.begin(), E = Uu.end(); It != E; ++It) { for (U::iterator It = Uu.begin(), E = Uu.end(); It != E; ++It) {
printf("s has value %d\n", (*It).X); printf("s has value %d\n", (*It).X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Uu) // CHECK-FIXES: for (auto & It : Uu)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
U::iterator A; U::iterator A;
for (U::iterator I = Uu.begin(), E = Uu.end(); I != E; ++I) for (U::iterator I = Uu.begin(), E = Uu.end(); I != E; ++I)
int K = A->X + I->X; int K = A->X + I->X;
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Uu) // CHECK-FIXES: for (auto & I : Uu)
// CHECK-FIXES-NEXT: int K = A->X + Elem.X; // CHECK-FIXES-NEXT: int K = A->X + I.X;
dependent<int> V; dependent<int> V;
for (dependent<int>::iterator It = V.begin(), E = V.end(); for (dependent<int>::iterator It = V.begin(), E = V.end();
@ -333,16 +333,16 @@ void f() {
printf("Fibonacci number is %d\n", *It); printf("Fibonacci number is %d\n", *It);
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : V) // CHECK-FIXES: for (int & It : V)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);
for (dependent<int>::iterator It(V.begin()), E = V.end(); for (dependent<int>::iterator It(V.begin()), E = V.end();
It != E; ++It) { It != E; ++It) {
printf("Fibonacci number is %d\n", *It); printf("Fibonacci number is %d\n", *It);
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : V) // CHECK-FIXES: for (int & It : V)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);
doublyDependent<int, int> Intmap; doublyDependent<int, int> Intmap;
for (doublyDependent<int, int>::iterator It = Intmap.begin(), E = Intmap.end(); for (doublyDependent<int, int>::iterator It = Intmap.begin(), E = Intmap.end();
@ -350,8 +350,8 @@ void f() {
printf("Intmap[%d] = %d", It->first, It->second); printf("Intmap[%d] = %d", It->first, It->second);
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Intmap) // CHECK-FIXES: for (auto & It : Intmap)
// CHECK-FIXES: printf("Intmap[%d] = %d", Elem.first, Elem.second); // CHECK-FIXES: printf("Intmap[%d] = %d", It.first, It.second);
// PtrSet's iterator dereferences by value so auto & can't be used. // PtrSet's iterator dereferences by value so auto & can't be used.
{ {
@ -395,15 +395,15 @@ void f() {
printf("%d\n", (**I).X); printf("%d\n", (**I).X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Dpp) // CHECK-FIXES: for (auto & I : Dpp)
// CHECK-FIXES-NEXT: printf("%d\n", (*Elem).X); // CHECK-FIXES-NEXT: printf("%d\n", (*I).X);
for (dependent<Val *>::iterator I = Dpp.begin(), E = Dpp.end(); I != E; ++I) { for (dependent<Val *>::iterator I = Dpp.begin(), E = Dpp.end(); I != E; ++I) {
printf("%d\n", (*I)->X); printf("%d\n", (*I)->X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Dpp) // CHECK-FIXES: for (auto & I : Dpp)
// CHECK-FIXES-NEXT: printf("%d\n", Elem->X); // CHECK-FIXES-NEXT: printf("%d\n", I->X);
} }
// Tests to verify the proper use of auto where the init variable type and the // Tests to verify the proper use of auto where the init variable type and the
@ -416,8 +416,8 @@ void different_type() {
printf("s has value %d\n", (*It).X); printf("s has value %d\n", (*It).X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto Elem : Ss) // CHECK-FIXES: for (auto It : Ss)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
S *Ps; S *Ps;
for (S::const_iterator It = Ps->begin(), E = Ps->end(); It != E; ++It) { for (S::const_iterator It = Ps->begin(), E = Ps->end(); It != E; ++It) {
@ -462,12 +462,12 @@ public:
for (iterator I = begin(), E = end(); I != E; ++I) for (iterator I = begin(), E = end(); I != E; ++I)
(void) *I; (void) *I;
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : *this) // CHECK-FIXES: for (auto & I : *this)
for (iterator I = C::begin(), E = C::end(); I != E; ++I) for (iterator I = C::begin(), E = C::end(); I != E; ++I)
(void) *I; (void) *I;
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : *this) // CHECK-FIXES: for (auto & I : *this)
for (iterator I = begin(), E = end(); I != E; ++I) { for (iterator I = begin(), E = end(); I != E; ++I) {
(void) *I; (void) *I;
@ -477,7 +477,7 @@ public:
for (iterator I = begin(); I != end(); ++I) for (iterator I = begin(); I != end(); ++I)
(void) *I; (void) *I;
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : *this) // CHECK-FIXES: for (auto & I : *this)
for (iterator I = begin(); I != end(); ++I) { for (iterator I = begin(); I != end(); ++I) {
(void) *I; (void) *I;
@ -489,12 +489,12 @@ public:
for (const_iterator I = begin(), E = end(); I != E; ++I) for (const_iterator I = begin(), E = end(); I != E; ++I)
(void) *I; (void) *I;
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto Elem : *this) // CHECK-FIXES: for (auto I : *this)
for (const_iterator I = C::begin(), E = C::end(); I != E; ++I) for (const_iterator I = C::begin(), E = C::end(); I != E; ++I)
(void) *I; (void) *I;
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto Elem : *this) // CHECK-FIXES: for (auto I : *this)
for (const_iterator I = begin(), E = end(); I != E; ++I) { for (const_iterator I = begin(), E = end(); I != E; ++I) {
(void) *I; (void) *I;
@ -516,7 +516,7 @@ public:
for (iterator I = begin(), E = end(); I != E; ++I) for (iterator I = begin(), E = end(); I != E; ++I)
(void) *I; (void) *I;
// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : *this) // CHECK-FIXES: for (auto & I : *this)
} }
}; };
@ -539,27 +539,27 @@ void f() {
Sum += V[I] + 2; Sum += V[I] + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : V) // CHECK-FIXES: for (int I : V)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
// CHECK-FIXES-NEXT: Sum += Elem + 2; // CHECK-FIXES-NEXT: Sum += I + 2;
for (int I = 0, E = V.size(); I < E; ++I) { for (int I = 0, E = V.size(); I < E; ++I) {
printf("Fibonacci number is %d\n", V.at(I)); printf("Fibonacci number is %d\n", V.at(I));
Sum += V.at(I) + 2; Sum += V.at(I) + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : V) // CHECK-FIXES: for (int I : V)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
// CHECK-FIXES-NEXT: Sum += Elem + 2; // CHECK-FIXES-NEXT: Sum += I + 2;
for (int I = 0, E = Pv->size(); I < E; ++I) { for (int I = 0, E = Pv->size(); I < E; ++I) {
printf("Fibonacci number is %d\n", Pv->at(I)); printf("Fibonacci number is %d\n", Pv->at(I));
Sum += Pv->at(I) + 2; Sum += Pv->at(I) + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : *Pv) // CHECK-FIXES: for (int I : *Pv)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
// CHECK-FIXES-NEXT: Sum += Elem + 2; // CHECK-FIXES-NEXT: Sum += I + 2;
// This test will fail if size() isn't called repeatedly, since it // This test will fail if size() isn't called repeatedly, since it
// returns unsigned int, and 0 is deduced to be signed int. // returns unsigned int, and 0 is deduced to be signed int.
@ -570,18 +570,18 @@ void f() {
Sum += (*Pv)[I] + 2; Sum += (*Pv)[I] + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : *Pv) // CHECK-FIXES: for (int I : *Pv)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
// CHECK-FIXES-NEXT: Sum += Elem + 2; // CHECK-FIXES-NEXT: Sum += I + 2;
for (int I = 0; I < Cv->size(); ++I) { for (int I = 0; I < Cv->size(); ++I) {
printf("Fibonacci number is %d\n", Cv->at(I)); printf("Fibonacci number is %d\n", Cv->at(I));
Sum += Cv->at(I) + 2; Sum += Cv->at(I) + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : *Cv) // CHECK-FIXES: for (int I : *Cv)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
// CHECK-FIXES-NEXT: Sum += Elem + 2; // CHECK-FIXES-NEXT: Sum += I + 2;
} }
// Ensure that 'const auto &' is used with containers of non-trivial types. // Ensure that 'const auto &' is used with containers of non-trivial types.
@ -592,27 +592,27 @@ void constness() {
Sum += Constv[I].X + 2; Sum += Constv[I].X + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (const auto & Elem : Constv) // CHECK-FIXES: for (const auto & I : Constv)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I.X);
// CHECK-FIXES-NEXT: Sum += Elem.X + 2; // CHECK-FIXES-NEXT: Sum += I.X + 2;
for (int I = 0, E = Constv.size(); I < E; ++I) { for (int I = 0, E = Constv.size(); I < E; ++I) {
printf("Fibonacci number is %d\n", Constv.at(I).X); printf("Fibonacci number is %d\n", Constv.at(I).X);
Sum += Constv.at(I).X + 2; Sum += Constv.at(I).X + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (const auto & Elem : Constv) // CHECK-FIXES: for (const auto & I : Constv)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I.X);
// CHECK-FIXES-NEXT: Sum += Elem.X + 2; // CHECK-FIXES-NEXT: Sum += I.X + 2;
for (int I = 0, E = Pconstv->size(); I < E; ++I) { for (int I = 0, E = Pconstv->size(); I < E; ++I) {
printf("Fibonacci number is %d\n", Pconstv->at(I).X); printf("Fibonacci number is %d\n", Pconstv->at(I).X);
Sum += Pconstv->at(I).X + 2; Sum += Pconstv->at(I).X + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (const auto & Elem : *Pconstv) // CHECK-FIXES: for (const auto & I : *Pconstv)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I.X);
// CHECK-FIXES-NEXT: Sum += Elem.X + 2; // CHECK-FIXES-NEXT: Sum += I.X + 2;
// This test will fail if size() isn't called repeatedly, since it // This test will fail if size() isn't called repeatedly, since it
// returns unsigned int, and 0 is deduced to be signed int. // returns unsigned int, and 0 is deduced to be signed int.
@ -623,28 +623,28 @@ void constness() {
Sum += (*Pconstv)[I].X + 2; Sum += (*Pconstv)[I].X + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (const auto & Elem : *Pconstv) // CHECK-FIXES: for (const auto & I : *Pconstv)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I.X);
// CHECK-FIXES-NEXT: Sum += Elem.X + 2; // CHECK-FIXES-NEXT: Sum += I.X + 2;
} }
void constRef(const dependent<int>& ConstVRef) { void constRef(const dependent<int>& ConstVRef) {
int sum = 0; int sum = 0;
// FIXME: This does not work with size_t (probably due to the implementation // FIXME: This does not work with size_t (probably due to the implementation
// of dependent); make dependent work exactly like a std container type. // of dependent); make dependent work exactly like a std container type.
for (int i = 0; i < ConstVRef.size(); ++i) { for (int I = 0; I < ConstVRef.size(); ++I) {
sum += ConstVRef[i]; sum += ConstVRef[I];
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : ConstVRef) // CHECK-FIXES: for (int I : ConstVRef)
// CHECK-FIXES-NEXT: sum += Elem; // CHECK-FIXES-NEXT: sum += I;
for (auto I = ConstVRef.begin(), E = ConstVRef.end(); I != E; ++I) { for (auto I = ConstVRef.begin(), E = ConstVRef.end(); I != E; ++I) {
sum += *I; sum += *I;
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : ConstVRef) // CHECK-FIXES: for (int I : ConstVRef)
// CHECK-FIXES-NEXT: sum += Elem; // CHECK-FIXES-NEXT: sum += I;
} }
// Check for loops that don't mention containers. // Check for loops that don't mention containers.
@ -695,15 +695,15 @@ void NoBeginEndTest() {
for (unsigned I = 0, E = CBE.size(); I < E; ++I) for (unsigned I = 0, E = CBE.size(); I < E; ++I)
printf("%d\n", CBE[I]); printf("%d\n", CBE[I]);
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (unsigned int Elem : CBE) // CHECK-FIXES: for (unsigned int I : CBE)
// CHECK-FIXES-NEXT: printf("%d\n", Elem); // CHECK-FIXES-NEXT: printf("%d\n", I);
const ConstBeginEnd Const_CBE; const ConstBeginEnd Const_CBE;
for (unsigned I = 0, E = Const_CBE.size(); I < E; ++I) for (unsigned I = 0, E = Const_CBE.size(); I < E; ++I)
printf("%d\n", Const_CBE[I]); printf("%d\n", Const_CBE[I]);
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (unsigned int Elem : Const_CBE) // CHECK-FIXES: for (unsigned int I : Const_CBE)
// CHECK-FIXES-NEXT: printf("%d\n", Elem); // CHECK-FIXES-NEXT: printf("%d\n", I);
} }
struct DerefByValue { struct DerefByValue {
@ -721,17 +721,17 @@ void derefByValueTest() {
printf("%d\n", DBV[I]); printf("%d\n", DBV[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (unsigned int Elem : DBV) // CHECK-FIXES: for (unsigned int I : DBV)
// CHECK-FIXES-NEXT: printf("%d\n", Elem); // CHECK-FIXES-NEXT: printf("%d\n", I);
for (unsigned I = 0, E = DBV.size(); I < E; ++I) { for (unsigned I = 0, E = DBV.size(); I < E; ++I) {
auto f = [DBV, I]() {}; auto f = [DBV, I]() {};
printf("%d\n", DBV[I]); printf("%d\n", DBV[I]);
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (unsigned int Elem : DBV) // CHECK-FIXES: for (unsigned int I : DBV)
// CHECK-FIXES-NEXT: auto f = [DBV, &Elem]() {}; // CHECK-FIXES-NEXT: auto f = [DBV, &I]() {};
// CHECK-FIXES-NEXT: printf("%d\n", Elem); // CHECK-FIXES-NEXT: printf("%d\n", I);
} }
void fundamentalTypesTest() { void fundamentalTypesTest() {

View File

@ -13,8 +13,8 @@ void naming() {
printf("%d\n", arr[i]); printf("%d\n", arr[i]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert] // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
// CHECK-FIXES: for (int elem : arr) // CHECK-FIXES: for (int i : arr)
// CHECK-FIXES-NEXT: printf("%d\n", elem); // CHECK-FIXES-NEXT: printf("%d\n", i);
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
printf("%d\n", nums[i]); printf("%d\n", nums[i]);
@ -28,50 +28,6 @@ void naming() {
printf("%d\n", nums[i] + num); printf("%d\n", nums[i] + num);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int elem : nums) // CHECK-FIXES: for (int i : nums)
// CHECK-FIXES-NEXT: printf("%d\n", elem + num); // CHECK-FIXES-NEXT: printf("%d\n", i + 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
// CHECK-FIXES: for (int numsI : nums)
// CHECK-FIXES-NEXT: printf("%d\n", numsI + num + elem);
int numsI = 0;
for (int i = 0; i < n; ++i) {
printf("%d\n", nums[i] + num + elem + numsI);
}
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int numsElem : nums)
// CHECK-FIXES-NEXT: printf("%d\n", numsElem + num + elem + numsI);
int numsElem = 0;
for (int i = 0; i < n; ++i) {
printf("%d\n", nums[i] + num + elem + numsI + numsElem);
}
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int giveMeName0 : nums)
// CHECK-FIXES-NEXT: printf("%d\n", giveMeName0 + num + elem + numsI + numsElem);
int giveMeName0 = 0;
for (int i = 0; i < n; ++i) {
printf("%d\n", nums[i] + num + elem + numsI + numsElem + giveMeName0);
}
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int giveMeName1 : nums)
// CHECK-FIXES-NEXT: printf("%d\n", giveMeName1 + num + elem + numsI + numsElem + giveMeName0);
int numsJ = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
printf("%d\n", nums[i] + nums[j] + num + elem + numsI + numsJ + numsElem);
}
}
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-MESSAGES: :[[@LINE-5]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (int giveMeName0 : nums)
// CHECK-FIXES: for (int giveMeName1 : nums)
// CHECK-FIXES-NEXT: printf("%d\n", giveMeName0 + giveMeName1 + num + elem + numsI + numsJ + numsElem);
} }

View File

@ -43,45 +43,45 @@ void memberFunctionsAndOperators() {
Array[I].constMember(0); Array[I].constMember(0);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert] // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
// CHECK-FIXES: for (auto Elem : Array) // CHECK-FIXES: for (auto I : Array)
// CHECK-FIXES-NEXT: Elem.constMember(0); // CHECK-FIXES-NEXT: I.constMember(0);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
if (Array[I] < OtherStr) if (Array[I] < OtherStr)
foo(); foo();
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto Elem : Array) // CHECK-FIXES: for (auto I : Array)
// CHECK-FIXES-NEXT: if (Elem < OtherStr) // CHECK-FIXES-NEXT: if (I < OtherStr)
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
if (Right[I] < OtherRight) if (Right[I] < OtherRight)
foo(); foo();
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop
// CHECK-FIXES: for (const auto & Elem : Right) // CHECK-FIXES: for (const auto & I : Right)
// CHECK-FIXES-NEXT: if (Elem < OtherRight) // CHECK-FIXES-NEXT: if (I < OtherRight)
// Calling non-const member functions is not. // Calling non-const member functions is not.
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
Array[I].nonConstMember(0); Array[I].nonConstMember(0);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto & Elem : Array) // CHECK-FIXES: for (auto & I : Array)
// CHECK-FIXES-NEXT: Elem.nonConstMember(0); // CHECK-FIXES-NEXT: I.nonConstMember(0);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
Array[I] = OtherStr; Array[I] = OtherStr;
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto & Elem : Array) // CHECK-FIXES: for (auto & I : Array)
// CHECK-FIXES-NEXT: Elem = OtherStr; // CHECK-FIXES-NEXT: I = OtherStr;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
Right[I] = OtherRight; Right[I] = OtherRight;
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto & Elem : Right) // CHECK-FIXES: for (auto & I : Right)
// CHECK-FIXES-NEXT: Elem = OtherRight; // CHECK-FIXES-NEXT: I = OtherRight;
} }
void usedAsParameterToFunctionOrOperator() { void usedAsParameterToFunctionOrOperator() {
@ -90,59 +90,59 @@ void usedAsParameterToFunctionOrOperator() {
copyArg(Array[I]); copyArg(Array[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto Elem : Array) // CHECK-FIXES: for (auto I : Array)
// CHECK-FIXES-NEXT: copyArg(Elem); // CHECK-FIXES-NEXT: copyArg(I);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
copyArg(Right[I]); copyArg(Right[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto & Elem : Right) // CHECK-FIXES: for (auto & I : Right)
// CHECK-FIXES-NEXT: copyArg(Elem); // CHECK-FIXES-NEXT: copyArg(I);
// Using as a const reference argument is allowed. // Using as a const reference argument is allowed.
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
constRefArg(Array[I]); constRefArg(Array[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto Elem : Array) // CHECK-FIXES: for (auto I : Array)
// CHECK-FIXES-NEXT: constRefArg(Elem); // CHECK-FIXES-NEXT: constRefArg(I);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
if (OtherStr < Array[I]) if (OtherStr < Array[I])
foo(); foo();
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto Elem : Array) // CHECK-FIXES: for (auto I : Array)
// CHECK-FIXES-NEXT: if (OtherStr < Elem) // CHECK-FIXES-NEXT: if (OtherStr < I)
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
constRefArg(Right[I]); constRefArg(Right[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop
// CHECK-FIXES: for (const auto & Elem : Right) // CHECK-FIXES: for (const auto & I : Right)
// CHECK-FIXES-NEXT: constRefArg(Elem); // CHECK-FIXES-NEXT: constRefArg(I);
// Using as a non-const reference is not. // Using as a non-const reference is not.
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
nonConstRefArg(Array[I]); nonConstRefArg(Array[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto & Elem : Array) // CHECK-FIXES: for (auto & I : Array)
// CHECK-FIXES-NEXT: nonConstRefArg(Elem); // CHECK-FIXES-NEXT: nonConstRefArg(I);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
nonConstRefArg(Right[I]); nonConstRefArg(Right[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto & Elem : Right) // CHECK-FIXES: for (auto & I : Right)
// CHECK-FIXES-NEXT: nonConstRefArg(Elem); // CHECK-FIXES-NEXT: nonConstRefArg(I);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
if (OtherRight < Right[I]) if (OtherRight < Right[I])
foo(); foo();
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto & Elem : Right) // CHECK-FIXES: for (auto & I : Right)
// CHECK-FIXES-NEXT: if (OtherRight < Elem) // CHECK-FIXES-NEXT: if (OtherRight < I)
} }
void primitiveTypes() { void primitiveTypes() {
@ -238,17 +238,17 @@ void takingReferences() {
Str &K = Array[I]; Str &K = Array[I];
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto & Elem : Array) // CHECK-FIXES: for (auto & I : Array)
// CHECK-FIXES-NEXT: Str &J = Elem; // CHECK-FIXES-NEXT: Str &J = I;
// CHECK-FIXES-NEXT: Str &K = Elem; // CHECK-FIXES-NEXT: Str &K = I;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
const Str &J = Array[I]; const Str &J = Array[I];
const Str &K = Array[I]; const Str &K = Array[I];
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop
// CHECK-FIXES: for (auto Elem : Array) // CHECK-FIXES: for (auto I : Array)
// CHECK-FIXES-NEXT: const Str &J = Elem; // CHECK-FIXES-NEXT: const Str &J = I;
// CHECK-FIXES-NEXT: const Str &K = Elem; // CHECK-FIXES-NEXT: const Str &K = I;
// Primitive type. // Primitive type.
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
@ -309,7 +309,7 @@ struct vector {
}; };
// If the elements are already constant, we won't do any ImplicitCast to const. // If the elements are already constant, we won't do any ImplicitCast to const.
void testContainerOfConstElements() { void testContainerOfConstIents() {
const int Ints[N]{}; const int Ints[N]{};
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
OtherInt -= Ints[I]; OtherInt -= Ints[I];
@ -348,14 +348,13 @@ class TestInsideConstFunction {
constRefArg(Array[I]); constRefArg(Array[I]);
} }
// CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop
// CHECK-FIXES: for (auto Elem : Array) // CHECK-FIXES: for (auto I : Array)
for (int I = 0; I < V.size(); ++I) { for (int I = 0; I < V.size(); ++I) {
if (V[I]) if (V[I])
copyArg(V[I]); copyArg(V[I]);
} }
// CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop
// CHECK-FIXES: for (int Elem : V) // CHECK-FIXES: for (int I : V)
} }
}; };

View File

@ -14,9 +14,9 @@ void f() {
int B = Arr[I][A]; int B = Arr[I][A];
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Arr) // CHECK-FIXES: for (auto & I : Arr)
// CHECK-FIXES-NEXT: int A = 0; // CHECK-FIXES-NEXT: int A = 0;
// CHECK-FIXES-NEXT: int B = Elem[A]; // CHECK-FIXES-NEXT: int B = I[A];
for (int J = 0; J < M; ++J) { for (int J = 0; J < M; ++J) {
int A = 0; int A = 0;
@ -64,10 +64,10 @@ void aliasing() {
int Z = Arr[I].X + T.X; int Z = Arr[I].X + T.X;
} }
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Arr) // CHECK-FIXES: for (auto & I : Arr)
// CHECK-FIXES-NEXT: Val &T = Elem; // CHECK-FIXES-NEXT: Val &T = I;
// CHECK-FIXES-NEXT: int Y = T.X; // CHECK-FIXES-NEXT: int Y = T.X;
// CHECK-FIXES-NEXT: int Z = Elem.X + T.X; // CHECK-FIXES-NEXT: int Z = I.X + T.X;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
Val T = Arr[I]; Val T = Arr[I];
@ -75,10 +75,10 @@ void aliasing() {
int Z = Arr[I].X + T.X; int Z = Arr[I].X + T.X;
} }
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Arr) // CHECK-FIXES: for (auto & I : Arr)
// CHECK-FIXES-NEXT: Val T = Elem; // CHECK-FIXES-NEXT: Val T = I;
// CHECK-FIXES-NEXT: int Y = T.X; // CHECK-FIXES-NEXT: int Y = T.X;
// CHECK-FIXES-NEXT: int Z = Elem.X + T.X; // CHECK-FIXES-NEXT: int Z = I.X + T.X;
// The same for pseudo-arrays like std::vector<T> (or here dependent<Val>) // The same for pseudo-arrays like std::vector<T> (or here dependent<Val>)
// which provide a subscript operator[]. // which provide a subscript operator[].
@ -108,8 +108,8 @@ void aliasing() {
int Y = T.X; int Y = T.X;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Arr) // CHECK-FIXES: for (auto & I : Arr)
// CHECK-FIXES-NEXT: Val &T = func(Elem); // CHECK-FIXES-NEXT: Val &T = func(I);
// CHECK-FIXES-NEXT: int Y = T.X; // CHECK-FIXES-NEXT: int Y = T.X;
int IntArr[N]; int IntArr[N];
@ -164,8 +164,8 @@ void aliasing() {
IntRef Int(IntArr[I]); IntRef Int(IntArr[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : IntArr) // CHECK-FIXES: for (int I : IntArr)
// CHECK-FIXES-NEXT: IntRef Int(Elem); // CHECK-FIXES-NEXT: IntRef Int(I);
// Ensure that removing the alias doesn't leave empty lines behind. // Ensure that removing the alias doesn't leave empty lines behind.
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
@ -227,8 +227,8 @@ void refs_and_vals() {
unsigned Othersize = Other.size(); unsigned Othersize = Other.size();
} }
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Dep) // CHECK-FIXES: for (int & It : Dep)
// CHECK-FIXES-NEXT: printf("%d\n", Elem); // CHECK-FIXES-NEXT: printf("%d\n", It);
// CHECK-FIXES-NEXT: const int& Idx = Other[0]; // CHECK-FIXES-NEXT: const int& Idx = Other[0];
// CHECK-FIXES-NEXT: unsigned Othersize = Other.size(); // CHECK-FIXES-NEXT: unsigned Othersize = Other.size();
@ -307,10 +307,10 @@ void sameNames() {
(void)Nums[I]; (void)Nums[I];
} }
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Nums) // CHECK-FIXES: for (int & I : Nums)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
// CHECK-FIXES-NEXT: Sum += Elem + 2 + Num; // CHECK-FIXES-NEXT: Sum += I + 2 + Num;
// CHECK-FIXES-NEXT: (void)Elem; // CHECK-FIXES-NEXT: (void)I;
int Elem = 0; int Elem = 0;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
@ -319,10 +319,10 @@ void sameNames() {
(void)Nums[I]; (void)Nums[I];
} }
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & NumsI : Nums) // CHECK-FIXES: for (int & I : Nums)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", NumsI); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
// CHECK-FIXES-NEXT: Sum += NumsI + 2 + Num + Elem; // CHECK-FIXES-NEXT: Sum += I + 2 + Num + Elem;
// CHECK-FIXES-NEXT: (void)NumsI; // CHECK-FIXES-NEXT: (void)I;
} }
void oldIndexConflict() { void oldIndexConflict() {
@ -349,8 +349,8 @@ void macroConflict() {
printf("Max of 3 and 5: %d\n", MAX(3, 5)); printf("Max of 3 and 5: %d\n", MAX(3, 5));
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : MAXs) // CHECK-FIXES: for (auto & It : MAXs)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
// CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5)); // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5));
for (S::const_iterator It = MAXs.begin(), E = MAXs.end(); It != E; ++It) { for (S::const_iterator It = MAXs.begin(), E = MAXs.end(); It != E; ++It) {
@ -358,8 +358,8 @@ void macroConflict() {
printf("Max of 3 and 5: %d\n", MAX(3, 5)); printf("Max of 3 and 5: %d\n", MAX(3, 5));
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto Elem : MAXs) // CHECK-FIXES: for (auto It : MAXs)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
// CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5)); // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5));
T DEFs; T DEFs;
@ -369,9 +369,9 @@ void macroConflict() {
} }
} }
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : DEFs) // CHECK-FIXES: for (int & It : DEFs)
// CHECK-FIXES-NEXT: if (Elem == DEF) // CHECK-FIXES-NEXT: if (It == DEF)
// CHECK-FIXES-NEXT: printf("I found %d\n", Elem); // CHECK-FIXES-NEXT: printf("I found %d\n", It);
} }
void keywordConflict() { void keywordConflict() {
@ -380,8 +380,8 @@ void keywordConflict() {
*It = 5; *It = 5;
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : ints) // CHECK-FIXES: for (int & It : ints)
// CHECK-FIXES-NEXT: Elem = 5; // CHECK-FIXES-NEXT: It = 5;
U __FUNCTION__s; U __FUNCTION__s;
for (U::iterator It = __FUNCTION__s.begin(), E = __FUNCTION__s.end(); for (U::iterator It = __FUNCTION__s.begin(), E = __FUNCTION__s.end();
@ -389,8 +389,8 @@ void keywordConflict() {
int __FUNCTION__s_It = (*It).X + 2; int __FUNCTION__s_It = (*It).X + 2;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : __FUNCTION__s) // CHECK-FIXES: for (auto & It : __FUNCTION__s)
// CHECK-FIXES-NEXT: int __FUNCTION__s_It = Elem.X + 2; // CHECK-FIXES-NEXT: int __FUNCTION__s_It = It.X + 2;
} }
void typeConflict() { void typeConflict() {
@ -408,8 +408,8 @@ void typeConflict() {
*It = sizeof(Val); *It = sizeof(Val);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Vals) // CHECK-FIXES: for (int & It : Vals)
// CHECK-FIXES-NEXT: Elem = sizeof(Val); // CHECK-FIXES-NEXT: It = sizeof(Val);
typedef struct Val TD; typedef struct Val TD;
U TDs; U TDs;
@ -427,7 +427,7 @@ void typeConflict() {
(void) *It; (void) *It;
} }
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : TDs) // CHECK-FIXES: for (auto & It : TDs)
// CHECK-FIXES-NEXT: TD V; // CHECK-FIXES-NEXT: TD V;
// CHECK-FIXES-NEXT: V.X = 5; // CHECK-FIXES-NEXT: V.X = 5;
@ -437,8 +437,8 @@ void typeConflict() {
*It = sizeof(St); *It = sizeof(St);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Sts) // CHECK-FIXES: for (int & It : Sts)
// CHECK-FIXES-NEXT: Elem = sizeof(St); // CHECK-FIXES-NEXT: It = sizeof(St);
} }
} // namespace NamingConflict } // namespace NamingConflict
@ -501,10 +501,10 @@ void f() {
} }
// CHECK-MESSAGES: :[[@LINE-8]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-8]]:3: warning: use range-based for loop instead
// CHECK-MESSAGES: :[[@LINE-8]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-8]]:5: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Arr) // CHECK-FIXES: for (auto & I : Arr)
// CHECK-FIXES-NEXT: for (auto & ArrJ : Arr) // CHECK-FIXES-NEXT: for (auto & J : Arr)
// CHECK-FIXES-NEXT: int K = Elem.X + ArrJ.X; // CHECK-FIXES-NEXT: int K = I.X + J.X;
// CHECK-FIXES-NOT: int L = Elem.X + Elem.X; // CHECK-FIXES-NOT: int L = I.X + I.X;
// The inner loop is also convertible, but doesn't need to be converted // The inner loop is also convertible, but doesn't need to be converted
// immediately. FIXME: update this test when that changes. // immediately. FIXME: update this test when that changes.
@ -515,9 +515,9 @@ void f() {
} }
} }
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Nest) // CHECK-FIXES: for (auto & I : Nest)
// CHECK-FIXES-NEXT: for (int J = 0; J < M; ++J) // CHECK-FIXES-NEXT: for (int J = 0; J < M; ++J)
// CHECK-FIXES-NEXT: printf("Got item %d", Elem[J].X); // CHECK-FIXES-NEXT: printf("Got item %d", I[J].X);
// Note that the order of M and N are switched for this test. // Note that the order of M and N are switched for this test.
for (int J = 0; J < M; ++J) { for (int J = 0; J < M; ++J) {
@ -528,8 +528,8 @@ void f() {
// CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop instead
// CHECK-FIXES-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[I]) // CHECK-FIXES-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[I])
// CHECK-FIXES: for (int J = 0; J < M; ++J) // CHECK-FIXES: for (int J = 0; J < M; ++J)
// CHECK-FIXES-NEXT: for (auto & Elem : Nest) // CHECK-FIXES-NEXT: for (auto & I : Nest)
// CHECK-FIXES-NEXT: printf("Got item %d", Elem[J].X); // CHECK-FIXES-NEXT: printf("Got item %d", I[J].X);
// The inner loop is also convertible. // The inner loop is also convertible.
Nested<T> NestT; Nested<T> NestT;
@ -539,8 +539,8 @@ void f() {
} }
} }
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : NestT) // CHECK-FIXES: for (auto & I : NestT)
// CHECK-FIXES-NEXT: for (T::iterator TI = Elem.begin(), TE = Elem.end(); TI != TE; ++TI) // CHECK-FIXES-NEXT: for (T::iterator TI = I.begin(), TE = I.end(); TI != TE; ++TI)
// CHECK-FIXES-NEXT: printf("%d", *TI); // CHECK-FIXES-NEXT: printf("%d", *TI);
// The inner loop is also convertible. // The inner loop is also convertible.
@ -551,8 +551,8 @@ void f() {
} }
} }
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto Elem : NestS) // CHECK-FIXES: for (auto I : NestS)
// CHECK-FIXES-NEXT: for (S::const_iterator SI = Elem.begin(), SE = Elem.end(); SI != SE; ++SI) // CHECK-FIXES-NEXT: for (S::const_iterator SI = I.begin(), SE = I.end(); SI != SE; ++SI)
// CHECK-FIXES-NEXT: printf("%d", *SI); // CHECK-FIXES-NEXT: printf("%d", *SI);
for (Nested<S>::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) { for (Nested<S>::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
@ -611,9 +611,9 @@ void complexContainer() {
MutableVal J = *I; MutableVal J = *I;
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Exes[Index].getS()) // CHECK-FIXES: for (auto & I : Exes[Index].getS())
// CHECK-FIXES-NEXT: MutableVal K = Elem; // CHECK-FIXES-NEXT: MutableVal K = I;
// CHECK-FIXES-NEXT: MutableVal J = Elem; // CHECK-FIXES-NEXT: MutableVal J = I;
} }
void f() { void f() {
@ -623,24 +623,24 @@ void f() {
printf("I found %d\n", *It); printf("I found %d\n", *It);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Tt) // CHECK-FIXES: for (int & It : Tt)
// CHECK-FIXES-NEXT: printf("I found %d\n", Elem); // CHECK-FIXES-NEXT: printf("I found %d\n", It);
T *Pt; T *Pt;
for (T::iterator It = Pt->begin(); It != Pt->end(); ++It) { for (T::iterator It = Pt->begin(); It != Pt->end(); ++It) {
printf("I found %d\n", *It); printf("I found %d\n", *It);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : *Pt) // CHECK-FIXES: for (int & It : *Pt)
// CHECK-FIXES-NEXT: printf("I found %d\n", Elem); // CHECK-FIXES-NEXT: printf("I found %d\n", It);
S Ss; S Ss;
for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) { for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) {
printf("s has value %d\n", (*It).X); printf("s has value %d\n", (*It).X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Ss) // CHECK-FIXES: for (auto & It : Ss)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
S *Ps; S *Ps;
for (S::iterator It = Ps->begin(); It != Ps->end(); ++It) { for (S::iterator It = Ps->begin(); It != Ps->end(); ++It) {
@ -654,51 +654,51 @@ void f() {
printf("s has value %d\n", It->X); printf("s has value %d\n", It->X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Ss) // CHECK-FIXES: for (auto & It : Ss)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) { for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) {
It->X = 3; It->X = 3;
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Ss) // CHECK-FIXES: for (auto & It : Ss)
// CHECK-FIXES-NEXT: Elem.X = 3; // CHECK-FIXES-NEXT: It.X = 3;
for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) { for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) {
(*It).X = 3; (*It).X = 3;
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Ss) // CHECK-FIXES: for (auto & It : Ss)
// CHECK-FIXES-NEXT: Elem.X = 3; // CHECK-FIXES-NEXT: It.X = 3;
for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) { for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) {
It->nonConstFun(4, 5); It->nonConstFun(4, 5);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Ss) // CHECK-FIXES: for (auto & It : Ss)
// CHECK-FIXES-NEXT: Elem.nonConstFun(4, 5); // CHECK-FIXES-NEXT: It.nonConstFun(4, 5);
U Uu; U Uu;
for (U::iterator It = Uu.begin(); It != Uu.end(); ++It) { for (U::iterator It = Uu.begin(); It != Uu.end(); ++It) {
printf("s has value %d\n", It->X); printf("s has value %d\n", It->X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Uu) // CHECK-FIXES: for (auto & It : Uu)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
for (U::iterator It = Uu.begin(); It != Uu.end(); ++It) { for (U::iterator It = Uu.begin(); It != Uu.end(); ++It) {
printf("s has value %d\n", (*It).X); printf("s has value %d\n", (*It).X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Uu) // CHECK-FIXES: for (auto & It : Uu)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
U::iterator A; U::iterator A;
for (U::iterator I = Uu.begin(); I != Uu.end(); ++I) for (U::iterator I = Uu.begin(); I != Uu.end(); ++I)
int K = A->X + I->X; int K = A->X + I->X;
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Uu) // CHECK-FIXES: for (auto & I : Uu)
// CHECK-FIXES-NEXT: int K = A->X + Elem.X; // CHECK-FIXES-NEXT: int K = A->X + I.X;
dependent<int> V; dependent<int> V;
for (dependent<int>::iterator It = V.begin(); for (dependent<int>::iterator It = V.begin();
@ -706,16 +706,16 @@ void f() {
printf("Fibonacci number is %d\n", *It); printf("Fibonacci number is %d\n", *It);
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : V) // CHECK-FIXES: for (int & It : V)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);
for (dependent<int>::iterator It(V.begin()); for (dependent<int>::iterator It(V.begin());
It != V.end(); ++It) { It != V.end(); ++It) {
printf("Fibonacci number is %d\n", *It); printf("Fibonacci number is %d\n", *It);
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : V) // CHECK-FIXES: for (int & It : V)
// CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);
doublyDependent<int, int> intmap; doublyDependent<int, int> intmap;
for (doublyDependent<int, int>::iterator It = intmap.begin(); for (doublyDependent<int, int>::iterator It = intmap.begin();
@ -723,8 +723,8 @@ void f() {
printf("intmap[%d] = %d", It->first, It->second); printf("intmap[%d] = %d", It->first, It->second);
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : intmap) // CHECK-FIXES: for (auto & It : intmap)
// CHECK-FIXES-NEXT: printf("intmap[%d] = %d", Elem.first, Elem.second); // CHECK-FIXES-NEXT: printf("intmap[%d] = %d", It.first, It.second);
} }
void different_type() { void different_type() {
@ -738,8 +738,8 @@ void different_type() {
printf("s has value %d\n", (*It).X); printf("s has value %d\n", (*It).X);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto Elem : Ss) // CHECK-FIXES: for (auto It : Ss)
// CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.X); // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
S *Ps; S *Ps;
for (S::const_iterator It = Ps->begin(); It != Ps->end(); ++It) { for (S::const_iterator It = Ps->begin(); It != Ps->end(); ++It) {
@ -778,8 +778,8 @@ void messing_with_macros() {
printf("Value: %d\n", Arr[I]); printf("Value: %d\n", Arr[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: printf("Value: %d\n", Elem); // CHECK-FIXES-NEXT: printf("Value: %d\n", I);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
printf("Value: %d\n", CONT Arr[I]); printf("Value: %d\n", CONT Arr[I]);
@ -791,9 +791,9 @@ void messing_with_macros() {
THREE_PARAM(Arr[I], Arr[I], Arr[I]); THREE_PARAM(Arr[I], Arr[I], Arr[I]);
} }
// CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES: for (int & I : Arr)
// CHECK-FIXES-NEXT: TWO_PARAM(Elem, Elem); // CHECK-FIXES-NEXT: TWO_PARAM(I, I);
// CHECK-FIXES-NEXT: THREE_PARAM(Elem, Elem, Elem); // CHECK-FIXES-NEXT: THREE_PARAM(I, I, I);
} }
} // namespace Macros } // namespace Macros
@ -811,7 +811,7 @@ void set_union(Container &container) {
for (S::iterator SI = Ss.begin(), SE = Ss.end(); SI != SE; ++SI) for (S::iterator SI = Ss.begin(), SE = Ss.end(); SI != SE; ++SI)
(void) *SI; (void) *SI;
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & Elem : Ss) // CHECK-FIXES: for (auto & SI : Ss)
} }
void template_instantiation() { void template_instantiation() {
@ -832,43 +832,43 @@ void capturesIndex() {
for (int I = 0; I < N; ++I) for (int I = 0; I < N; ++I)
auto F1 = [Arr, I]() { int R1 = Arr[I] + 1; }; auto F1 = [Arr, I]() { int R1 = Arr[I] + 1; };
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: auto F1 = [Arr, &Elem]() { int R1 = Elem + 1; }; // CHECK-FIXES-NEXT: auto F1 = [Arr, &I]() { int R1 = I + 1; };
for (int I = 0; I < N; ++I) for (int I = 0; I < N; ++I)
auto F2 = [Arr, &I]() { int R2 = Arr[I] + 3; }; auto F2 = [Arr, &I]() { int R2 = Arr[I] + 3; };
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: auto F2 = [Arr, &Elem]() { int R2 = Elem + 3; }; // CHECK-FIXES-NEXT: auto F2 = [Arr, &I]() { int R2 = I + 3; };
// FIXME: alias don't work if the index is captured. // FIXME: alias don't work if the index is captured.
// Alias declared inside lambda (by value). // Alias declared inside lambda (by value).
for (int I = 0; I < N; ++I) for (int I = 0; I < N; ++I)
auto F3 = [&Arr, I]() { int R3 = Arr[I]; }; auto F3 = [&Arr, I]() { int R3 = Arr[I]; };
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: auto F3 = [&Arr, &Elem]() { int R3 = Elem; }; // CHECK-FIXES-NEXT: auto F3 = [&Arr, &I]() { int R3 = I; };
for (int I = 0; I < N; ++I) for (int I = 0; I < N; ++I)
auto F4 = [&Arr, &I]() { int R4 = Arr[I]; }; auto F4 = [&Arr, &I]() { int R4 = Arr[I]; };
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: auto F4 = [&Arr, &Elem]() { int R4 = Elem; }; // CHECK-FIXES-NEXT: auto F4 = [&Arr, &I]() { int R4 = I; };
// Alias declared inside lambda (by reference). // Alias declared inside lambda (by reference).
for (int I = 0; I < N; ++I) for (int I = 0; I < N; ++I)
auto F5 = [&Arr, I]() { int &R5 = Arr[I]; }; auto F5 = [&Arr, I]() { int &R5 = Arr[I]; };
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES: for (int & I : Arr)
// CHECK-FIXES-NEXT: auto F5 = [&Arr, &Elem]() { int &R5 = Elem; }; // CHECK-FIXES-NEXT: auto F5 = [&Arr, &I]() { int &R5 = I; };
for (int I = 0; I < N; ++I) for (int I = 0; I < N; ++I)
auto F6 = [&Arr, &I]() { int &R6 = Arr[I]; }; auto F6 = [&Arr, &I]() { int &R6 = Arr[I]; };
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES: for (int & I : Arr)
// CHECK-FIXES-NEXT: auto F6 = [&Arr, &Elem]() { int &R6 = Elem; }; // CHECK-FIXES-NEXT: auto F6 = [&Arr, &I]() { int &R6 = I; };
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
auto F = [Arr, I](int k) { auto F = [Arr, I](int k) {
@ -877,10 +877,10 @@ void capturesIndex() {
F(Arr[I]); F(Arr[I]);
} }
// CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: auto F = [Arr, &Elem](int k) // CHECK-FIXES-NEXT: auto F = [Arr, &I](int k)
// CHECK-FIXES-NEXT: printf("%d\n", Elem + k); // CHECK-FIXES-NEXT: printf("%d\n", I + k);
// CHECK-FIXES: F(Elem); // CHECK-FIXES: F(I);
} }
void implicitCapture() { void implicitCapture() {
@ -909,10 +909,10 @@ void implicitCapture() {
}; };
} }
// CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: auto G3 = [&]() // CHECK-FIXES-NEXT: auto G3 = [&]()
// CHECK-FIXES-NEXT: int R3 = Elem; // CHECK-FIXES-NEXT: int R3 = I;
// CHECK-FIXES-NEXT: int J3 = Elem + R3; // CHECK-FIXES-NEXT: int J3 = I + R3;
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
auto G4 = [=]() { auto G4 = [=]() {
@ -920,9 +920,9 @@ void implicitCapture() {
}; };
} }
// CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: auto G4 = [=]() // CHECK-FIXES-NEXT: auto G4 = [=]()
// CHECK-FIXES-NEXT: int R4 = Elem + 5; // CHECK-FIXES-NEXT: int R4 = I + 5;
// Alias by value. // Alias by value.
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
@ -955,14 +955,14 @@ void iterators() {
for (dependent<int>::iterator I = Dep.begin(), E = Dep.end(); I != E; ++I) for (dependent<int>::iterator I = Dep.begin(), E = Dep.end(); I != E; ++I)
auto H1 = [&I]() { int R = *I; }; auto H1 = [&I]() { int R = *I; };
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Dep) // CHECK-FIXES: for (int & I : Dep)
// CHECK-FIXES-NEXT: auto H1 = [&Elem]() { int R = Elem; }; // CHECK-FIXES-NEXT: auto H1 = [&I]() { int R = I; };
for (dependent<int>::iterator I = Dep.begin(), E = Dep.end(); I != E; ++I) for (dependent<int>::iterator I = Dep.begin(), E = Dep.end(); I != E; ++I)
auto H2 = [&]() { int R = *I + 2; }; auto H2 = [&]() { int R = *I + 2; };
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int & Elem : Dep) // CHECK-FIXES: for (int & I : Dep)
// CHECK-FIXES-NEXT: auto H2 = [&]() { int R = Elem + 2; }; // CHECK-FIXES-NEXT: auto H2 = [&]() { int R = I + 2; };
// FIXME: It doesn't work with const iterators. // FIXME: It doesn't work with const iterators.
for (dependent<int>::const_iterator I = Dep.begin(), E = Dep.end(); for (dependent<int>::const_iterator I = Dep.begin(), E = Dep.end();
@ -991,15 +991,15 @@ void captureByValue() {
auto C1 = [&Arr, I]() { if (Arr[I] == 1); }; auto C1 = [&Arr, I]() { if (Arr[I] == 1); };
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Arr) // CHECK-FIXES: for (int I : Arr)
// CHECK-FIXES-NEXT: auto C1 = [&Arr, &Elem]() { if (Elem == 1); }; // CHECK-FIXES-NEXT: auto C1 = [&Arr, &I]() { if (I == 1); };
for (unsigned I = 0; I < Dep.size(); ++I) { for (unsigned I = 0; I < Dep.size(); ++I) {
auto C2 = [&Dep, I]() { if (Dep[I] == 2); }; auto C2 = [&Dep, I]() { if (Dep[I] == 2); };
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Dep) // CHECK-FIXES: for (int I : Dep)
// CHECK-FIXES-NEXT: auto C2 = [&Dep, &Elem]() { if (Elem == 2); }; // CHECK-FIXES-NEXT: auto C2 = [&Dep, &I]() { if (I == 2); };
} }
} // namespace Lambdas } // namespace Lambdas
@ -1024,12 +1024,12 @@ void f() {
E Ee{ { { g( { Array[I] } ) } } }; E Ee{ { { g( { Array[I] } ) } } };
} }
// CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int Elem : Array) // CHECK-FIXES: for (int I : Array)
// CHECK-FIXES-NEXT: int A{ Elem }; // CHECK-FIXES-NEXT: int A{ I };
// CHECK-FIXES-NEXT: int B{ g(Elem) }; // CHECK-FIXES-NEXT: int B{ g(I) };
// CHECK-FIXES-NEXT: int C{ g( { Elem } ) }; // CHECK-FIXES-NEXT: int C{ g( { I } ) };
// CHECK-FIXES-NEXT: D Dd{ { g( { Elem } ) } }; // CHECK-FIXES-NEXT: D Dd{ { g( { I } ) } };
// CHECK-FIXES-NEXT: E Ee{ { { g( { Elem } ) } } }; // CHECK-FIXES-NEXT: E Ee{ { { g( { I } ) } } };
} }
} // namespace InitLists } // namespace InitLists

View File

@ -14,8 +14,8 @@ void naming() {
printf("%d\n", arr[i]); printf("%d\n", arr[i]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert] // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
// CHECK-FIXES: for (int elem : arr) // CHECK-FIXES: for (int i : arr)
// CHECK-FIXES-NEXT: printf("%d\n", elem); // CHECK-FIXES-NEXT: printf("%d\n", i);
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
printf("%d\n", nums[i]); printf("%d\n", nums[i]);
@ -36,50 +36,6 @@ void naming() {
printf("%d\n", nums[i] + num); printf("%d\n", nums[i] + num);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int elem : nums) // CHECK-FIXES: for (int i : nums)
// CHECK-FIXES-NEXT: printf("%d\n", elem + num); // CHECK-FIXES-NEXT: printf("%d\n", i + 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
// CHECK-FIXES: for (int nums_i : nums)
// 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
// CHECK-FIXES: for (int nums_elem : nums)
// 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
// CHECK-FIXES: for (int give_me_name_0 : nums)
// 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
// CHECK-FIXES: for (int give_me_name_1 : nums)
// 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
// CHECK-FIXES: for (int give_me_name_0 : nums)
// CHECK-FIXES: for (int give_me_name_1 : nums)
// CHECK-FIXES-NEXT: printf("%d\n", give_me_name_0 + give_me_name_1 + num + elem + nums_i + nums_j + nums_elem);
} }

View File

@ -14,8 +14,8 @@ void naming() {
printf("%d\n", ARR[I]); printf("%d\n", ARR[I]);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert] // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
// CHECK-FIXES: for (int ELEM : ARR) // CHECK-FIXES: for (int I : ARR)
// CHECK-FIXES-NEXT: printf("%d\n", ELEM); // CHECK-FIXES-NEXT: printf("%d\n", I);
for (int I = 0; I < N; ++I) { for (int I = 0; I < N; ++I) {
printf("%d\n", NUMS[I]); printf("%d\n", NUMS[I]);
@ -36,50 +36,6 @@ void naming() {
printf("%d\n", NUMS[I] + NUM); printf("%d\n", NUMS[I] + NUM);
} }
// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (int ELEM : NUMS) // CHECK-FIXES: for (int I : NUMS)
// CHECK-FIXES-NEXT: printf("%d\n", ELEM + NUM); // CHECK-FIXES-NEXT: printf("%d\n", I + 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
// CHECK-FIXES: for (int NUMS_I : NUMS)
// 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
// CHECK-FIXES: for (int NUMS_ELEM : NUMS)
// 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
// CHECK-FIXES: for (int GIVE_ME_NAME_0 : NUMS)
// 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
// CHECK-FIXES: for (int GIVE_ME_NAME_1 : NUMS)
// 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
// CHECK-FIXES: for (int GIVE_ME_NAME_0 : NUMS)
// CHECK-FIXES: for (int GIVE_ME_NAME_1 : NUMS)
// CHECK-FIXES-NEXT: printf("%d\n", GIVE_ME_NAME_0 + GIVE_ME_NAME_1 + NUM + ELEM + NUMS_I + NUMS_J + NUMS_ELEM);
} }