From d8336f3af520f8f9831b4c2a1dacc0f89b8894e6 Mon Sep 17 00:00:00 2001 From: Angel Garcia Gomez Date: Thu, 22 Oct 2015 13:23:46 +0000 Subject: [PATCH] Don't use "auto" on loops over fundamental types in modernize-loop-convert. Summary: using "auto" on a loop that iterates over ints is kind of an overkill. Use the real type name instead. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13982 llvm-svn: 251015 --- .../clang-tidy/modernize/LoopConvertCheck.cpp | 37 +++--- .../clang-tidy/modernize/LoopConvertCheck.h | 2 +- .../modernize-loop-convert-basic.cpp | 110 +++++++++++++----- .../modernize-loop-convert-camelback.cpp | 18 +-- .../modernize-loop-convert-extra.cpp | 74 ++++++------ .../modernize-loop-convert-lowercase.cpp | 20 ++-- .../modernize-loop-convert-uppercase.cpp | 20 ++-- 7 files changed, 166 insertions(+), 115 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp index 2f37aa2804c7..81aa02872931 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp @@ -405,7 +405,7 @@ static bool containerIsConst(const Expr *ContainerExpr, bool Dereference) { LoopConvertCheck::RangeDescriptor::RangeDescriptor() : ContainerNeedsDereference(false), DerefByConstRef(false), - DerefByValue(false), IsTriviallyCopyable(false) {} + DerefByValue(false) {} LoopConvertCheck::LoopConvertCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), TUInfo(new TUTrackingInfo), @@ -554,30 +554,33 @@ void LoopConvertCheck::doConversion( // Now, we need to construct the new range expression. SourceRange ParenRange(Loop->getLParenLoc(), Loop->getRParenLoc()); - QualType AutoType = Context->getAutoDeductType(); + QualType Type = Context->getAutoDeductType(); + if (!Descriptor.ElemType.isNull() && Descriptor.ElemType->isFundamentalType()) + Type = Descriptor.ElemType.getUnqualifiedType(); // If the new variable name is from the aliased variable, then the reference // type for the new variable should only be used if the aliased variable was // declared as a reference. + bool IsTriviallyCopyable = + !Descriptor.ElemType.isNull() && + Descriptor.ElemType.isTriviallyCopyableType(*Context); bool UseCopy = - CanCopy && - ((VarNameFromAlias && !AliasVarIsRef) || - (Descriptor.DerefByConstRef && Descriptor.IsTriviallyCopyable)); + CanCopy && ((VarNameFromAlias && !AliasVarIsRef) || + (Descriptor.DerefByConstRef && IsTriviallyCopyable)); if (!UseCopy) { if (Descriptor.DerefByConstRef) { - AutoType = - Context->getLValueReferenceType(Context->getConstType(AutoType)); + Type = Context->getLValueReferenceType(Context->getConstType(Type)); } else if (Descriptor.DerefByValue) { - if (!Descriptor.IsTriviallyCopyable) - AutoType = Context->getRValueReferenceType(AutoType); + if (!IsTriviallyCopyable) + Type = Context->getRValueReferenceType(Type); } else { - AutoType = Context->getLValueReferenceType(AutoType); + Type = Context->getLValueReferenceType(Type); } } StringRef MaybeDereference = Descriptor.ContainerNeedsDereference ? "*" : ""; - std::string TypeString = AutoType.getAsString(); + std::string TypeString = Type.getAsString(getLangOpts()); std::string Range = ("(" + TypeString + " " + VarName + " : " + MaybeDereference + Descriptor.ContainerString + ")") .str(); @@ -633,7 +636,7 @@ void LoopConvertCheck::getArrayLoopQualifiers(ASTContext *Context, } Type = Type->getPointeeType(); } - Descriptor.IsTriviallyCopyable = Type.isTriviallyCopyableType(*Context); + Descriptor.ElemType = Type; } } @@ -654,8 +657,7 @@ void LoopConvertCheck::getIteratorLoopQualifiers(ASTContext *Context, // If the dereference operator returns by value then test for the // canonical const qualification of the init variable type. Descriptor.DerefByConstRef = CanonicalInitVarType.isConstQualified(); - Descriptor.IsTriviallyCopyable = - DerefByValueType->isTriviallyCopyableType(*Context); + Descriptor.ElemType = *DerefByValueType; } else { if (const auto *DerefType = Nodes.getNodeAs(DerefByRefResultName)) { @@ -665,8 +667,7 @@ void LoopConvertCheck::getIteratorLoopQualifiers(ASTContext *Context, auto ValueType = DerefType->getNonReferenceType(); Descriptor.DerefByConstRef = ValueType.isConstQualified(); - Descriptor.IsTriviallyCopyable = - ValueType.isTriviallyCopyableType(*Context); + Descriptor.ElemType = ValueType; } else { // By nature of the matcher this case is triggered only for built-in // iterator types (i.e. pointers). @@ -676,9 +677,7 @@ void LoopConvertCheck::getIteratorLoopQualifiers(ASTContext *Context, // We test for const qualification of the pointed-at type. Descriptor.DerefByConstRef = CanonicalInitVarType->getPointeeType().isConstQualified(); - Descriptor.IsTriviallyCopyable = - CanonicalInitVarType->getPointeeType().isTriviallyCopyableType( - *Context); + Descriptor.ElemType = CanonicalInitVarType->getPointeeType(); } } } diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h index 0337719fac08..cf8ca19b7b1e 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h @@ -30,8 +30,8 @@ private: bool ContainerNeedsDereference; bool DerefByConstRef; bool DerefByValue; - bool IsTriviallyCopyable; std::string ContainerString; + QualType ElemType; }; void getAliasRange(SourceManager &SM, SourceRange &DeclRange); diff --git a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp index 6f03acdc9f2b..713aaee78a63 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp @@ -18,7 +18,7 @@ void f() { int K; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead [modernize-loop-convert] - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: Sum += Elem; // CHECK-FIXES-NEXT: int K; @@ -27,7 +27,7 @@ void f() { Sum += Arr[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: Sum += Elem + 2; @@ -36,7 +36,7 @@ void f() { int Y = Arr[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: int X = Elem; // CHECK-FIXES-NEXT: int Y = Elem + 2; @@ -45,7 +45,7 @@ void f() { X = Arr[I]; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: int X = N; // CHECK-FIXES-NEXT: X = Elem; @@ -53,7 +53,7 @@ void f() { Arr[I] += 1; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: Elem += 1; for (int I = 0; I < N; ++I) { @@ -61,7 +61,7 @@ void f() { Arr[I]++; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: int X = Elem + 2; // CHECK-FIXES-NEXT: Elem++; @@ -69,14 +69,14 @@ void f() { Arr[I] = 4 + Arr[I]; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: Elem = 4 + Elem; for (int I = 0; I < NMinusOne + 1; ++I) { Sum += Arr[I]; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: Sum += Elem; for (int I = 0; I < N; ++I) { @@ -84,7 +84,7 @@ void f() { Sum += Arr[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", Elem, &Elem); // CHECK-FIXES-NEXT: Sum += Elem + 2; @@ -102,7 +102,7 @@ const int *constArray() { printf("2 * %d = %d\n", ConstArr[I], ConstArr[I] + ConstArr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Elem : ConstArr) + // CHECK-FIXES: for (int Elem : ConstArr) // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", Elem, Elem + Elem); const NonTriviallyCopyable NonCopy[N]{}; @@ -119,7 +119,7 @@ const int *constArray() { return &ConstArr[I]; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & Elem : ConstArr) + // CHECK-FIXES: for (const int & Elem : ConstArr) // CHECK-FIXES-NEXT: if (Something) // CHECK-FIXES-NEXT: return &Elem; } @@ -132,7 +132,7 @@ struct HasArr { printf("%d", Arr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: printf("%d", Elem); for (int I = 0; I < N; ++I) { @@ -148,7 +148,7 @@ struct HasArr { printf("%d", this->Arr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : this->Arr) + // CHECK-FIXES: for (int & Elem : this->Arr) // CHECK-FIXES-NEXT: printf("%d", Elem); for (int I = 0; I < N; ++I) { @@ -200,7 +200,7 @@ void f() { printf("I found %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Tt) + // CHECK-FIXES: for (int & Elem : Tt) // CHECK-FIXES-NEXT: printf("I found %d\n", Elem); T *Pt; @@ -208,7 +208,7 @@ void f() { printf("I found %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : *Pt) + // CHECK-FIXES: for (int & Elem : *Pt) // CHECK-FIXES-NEXT: printf("I found %d\n", Elem); S Ss; @@ -290,7 +290,7 @@ void f() { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : V) + // CHECK-FIXES: for (int & Elem : V) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); for (dependent::iterator It(V.begin()), E = V.end(); @@ -298,7 +298,7 @@ void f() { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : V) + // CHECK-FIXES: for (int & Elem : V) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); doublyDependent Intmap; @@ -333,7 +333,7 @@ void f() { (void) *I; } // CHECK-MESSAGES: :[[@LINE-5]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Int_ptr : Int_ptrs) + // CHECK-FIXES: for (int & Int_ptr : Int_ptrs) } { @@ -496,7 +496,7 @@ void f() { Sum += V[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : V) + // CHECK-FIXES: for (int & Elem : V) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: Sum += Elem + 2; @@ -505,7 +505,7 @@ void f() { Sum += V.at(I) + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : V) + // CHECK-FIXES: for (int & Elem : V) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: Sum += Elem + 2; @@ -514,7 +514,7 @@ void f() { Sum += Pv->at(I) + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : *Pv) + // CHECK-FIXES: for (int & Elem : *Pv) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: Sum += Elem + 2; @@ -527,7 +527,7 @@ void f() { Sum += (*Pv)[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : *Pv) + // CHECK-FIXES: for (int & Elem : *Pv) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: Sum += Elem + 2; @@ -536,7 +536,7 @@ void f() { Sum += Cv->at(I) + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : *Cv) + // CHECK-FIXES: for (int & Elem : *Cv) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: Sum += Elem + 2; } @@ -593,14 +593,14 @@ void constRef(const dependent& ConstVRef) { sum += ConstVRef[i]; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Elem : ConstVRef) + // CHECK-FIXES: for (int Elem : ConstVRef) // CHECK-FIXES-NEXT: sum += Elem; for (auto I = ConstVRef.begin(), E = ConstVRef.end(); I != E; ++I) { sum += *I; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Elem : ConstVRef) + // CHECK-FIXES: for (int Elem : ConstVRef) // CHECK-FIXES-NEXT: sum += Elem; } @@ -652,14 +652,14 @@ void NoBeginEndTest() { for (unsigned I = 0, E = CBE.size(); I < E; ++I) printf("%d\n", CBE[I]); // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : CBE) + // CHECK-FIXES: for (unsigned int & Elem : CBE) // CHECK-FIXES-NEXT: printf("%d\n", Elem); const ConstBeginEnd Const_CBE; for (unsigned I = 0, E = Const_CBE.size(); I < E; ++I) printf("%d\n", Const_CBE[I]); // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Elem : Const_CBE) + // CHECK-FIXES: for (unsigned int Elem : Const_CBE) // CHECK-FIXES-NEXT: printf("%d\n", Elem); } @@ -678,7 +678,7 @@ void derefByValueTest() { printf("%d\n", DBV[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Elem : DBV) + // CHECK-FIXES: for (unsigned int Elem : DBV) // CHECK-FIXES-NEXT: printf("%d\n", Elem); for (unsigned I = 0, E = DBV.size(); I < E; ++I) { @@ -686,9 +686,61 @@ void derefByValueTest() { printf("%d\n", DBV[I]); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Elem : DBV) + // CHECK-FIXES: for (unsigned int Elem : DBV) // CHECK-FIXES-NEXT: auto f = [DBV, &Elem]() {}; // CHECK-FIXES-NEXT: printf("%d\n", Elem); } +void fundamentalTypesTest() { + const int N = 10; + bool Bools[N]; + for (int i = 0; i < N; ++i) + printf("%d", Bools[i]); + // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (bool & Bool : Bools) + + int Ints[N]; + unsigned short int Shorts[N]; + for (int i = 0; i < N; ++i) + printf("%d", Shorts[i]); + // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (unsigned short & Short : Shorts) + + signed long Longs[N]; + for (int i = 0; i < N; ++i) + printf("%d", Longs[i]); + // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (long & Long : Longs) + + long long int LongLongs[N]; + for (int i = 0; i < N; ++i) + printf("%d", LongLongs[i]); + // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (long long & LongLong : LongLongs) + + char Chars[N]; + for (int i = 0; i < N; ++i) + printf("%d", Chars[i]); + // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (char & Char : Chars) + + wchar_t WChars[N]; + for (int i = 0; i < N; ++i) + printf("%d", WChars[i]); + // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (wchar_t & WChar : WChars) + + float Floats[N]; + for (int i = 0; i < N; ++i) + printf("%d", Floats[i]); + // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (float & Float : Floats) + + double Doubles[N]; + for (int i = 0; i < N; ++i) + printf("%d", Doubles[i]); + // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (double & Double : Doubles) +} + } // namespace PseudoArray diff --git a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-camelback.cpp b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-camelback.cpp index 786a3d3a5d16..eb5b3350bf2d 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-camelback.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-camelback.cpp @@ -13,14 +13,14 @@ void naming() { printf("%d\n", arr[i]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert] - // CHECK-FIXES: for (auto & elem : arr) + // CHECK-FIXES: for (int & elem : arr) // 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 - // CHECK-FIXES: for (auto & num : nums) + // CHECK-FIXES: for (int & num : nums) // CHECK-FIXES-NEXT: printf("%d\n", num); int num = 0; @@ -28,7 +28,7 @@ void naming() { printf("%d\n", nums[i] + num); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : nums) + // CHECK-FIXES: for (int & elem : nums) // CHECK-FIXES-NEXT: printf("%d\n", elem + num); int elem = 0; @@ -36,7 +36,7 @@ void naming() { printf("%d\n", nums[i] + num + elem); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & numsI : nums) + // CHECK-FIXES: for (int & numsI : nums) // CHECK-FIXES-NEXT: printf("%d\n", numsI + num + elem); int numsI = 0; @@ -44,7 +44,7 @@ void naming() { printf("%d\n", nums[i] + num + elem + numsI); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & numsElem : nums) + // CHECK-FIXES: for (int & numsElem : nums) // CHECK-FIXES-NEXT: printf("%d\n", numsElem + num + elem + numsI); int numsElem = 0; @@ -52,7 +52,7 @@ void naming() { printf("%d\n", nums[i] + num + elem + numsI + numsElem); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & giveMeName0 : nums) + // CHECK-FIXES: for (int & giveMeName0 : nums) // CHECK-FIXES-NEXT: printf("%d\n", giveMeName0 + num + elem + numsI + numsElem); int giveMeName0 = 0; @@ -60,7 +60,7 @@ void naming() { 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 (auto & giveMeName1 : nums) + // CHECK-FIXES: for (int & giveMeName1 : nums) // CHECK-FIXES-NEXT: printf("%d\n", giveMeName1 + num + elem + numsI + numsElem + giveMeName0); int numsJ = 0; @@ -71,7 +71,7 @@ void naming() { } // 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 (auto & giveMeName0 : nums) - // CHECK-FIXES: for (auto & giveMeName1 : nums) + // 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); } diff --git a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp index 518f51695b67..27c1011199c6 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp @@ -119,7 +119,7 @@ void aliasing() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Alias : IntArr) + // CHECK-FIXES: for (int Alias : IntArr) // CHECK-FIXES-NEXT: if (Alias) for (unsigned I = 0; I < N; ++I) { @@ -128,7 +128,7 @@ void aliasing() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Alias : IntArr) + // CHECK-FIXES: for (int Alias : IntArr) // CHECK-FIXES-NEXT: while (Alias) for (unsigned I = 0; I < N; ++I) { @@ -138,7 +138,7 @@ void aliasing() { } } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Alias : IntArr) + // CHECK-FIXES: for (int Alias : IntArr) // CHECK-FIXES-NEXT: switch (Alias) for (unsigned I = 0; I < N; ++I) { @@ -147,7 +147,7 @@ void aliasing() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Alias : IntArr) + // CHECK-FIXES: for (int Alias : IntArr) // CHECK-FIXES-NEXT: for (; Alias < N; ++Alias) for (unsigned I = 0; I < N; ++I) { @@ -156,7 +156,7 @@ void aliasing() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Alias : IntArr) + // CHECK-FIXES: for (int Alias : IntArr) // CHECK-FIXES-NEXT: for (unsigned J = 0; Alias; ++J) struct IntRef { IntRef(const int& i); }; @@ -164,7 +164,7 @@ void aliasing() { IntRef Int(IntArr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : IntArr) + // CHECK-FIXES: for (int & Elem : IntArr) // CHECK-FIXES-NEXT: IntRef Int(Elem); // Ensure that removing the alias doesn't leave empty lines behind. @@ -173,7 +173,7 @@ void aliasing() { X = 0; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & X : IntArr) { + // CHECK-FIXES: for (int & X : IntArr) { // CHECK-FIXES-NEXT: {{^ X = 0;$}} // CHECK-FIXES-NEXT: {{^ }$}} } @@ -227,7 +227,7 @@ void refs_and_vals() { unsigned Othersize = Other.size(); } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Dep) + // CHECK-FIXES: for (int & Elem : Dep) // CHECK-FIXES-NEXT: printf("%d\n", Elem); // CHECK-FIXES-NEXT: const int& Idx = Other[0]; // CHECK-FIXES-NEXT: unsigned Othersize = Other.size(); @@ -262,7 +262,7 @@ void sameNames() { (void)Nums[I]; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Nums) + // CHECK-FIXES: for (int & Elem : Nums) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); // CHECK-FIXES-NEXT: Sum += Elem + 2 + Num; // CHECK-FIXES-NEXT: (void)Elem; @@ -274,7 +274,7 @@ void sameNames() { (void)Nums[I]; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & NumsI : Nums) + // CHECK-FIXES: for (int & NumsI : Nums) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", NumsI); // CHECK-FIXES-NEXT: Sum += NumsI + 2 + Num + Elem; // CHECK-FIXES-NEXT: (void)NumsI; @@ -307,7 +307,7 @@ void macroConflict() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : DEFs) + // CHECK-FIXES: for (int & Elem : DEFs) // CHECK-FIXES-NEXT: if (Elem == DEF) // CHECK-FIXES-NEXT: printf("I found %d\n", Elem); } @@ -318,7 +318,7 @@ void keywordConflict() { *It = 5; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : ints) + // CHECK-FIXES: for (int & Elem : ints) // CHECK-FIXES-NEXT: Elem = 5; U __FUNCTION__s; @@ -338,7 +338,7 @@ void typeConflict() { for (T::iterator It = Vals.begin(), E = Vals.end(); It != E; ++It) (void) *It; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Val : Vals) + // CHECK-FIXES: for (int & Val : Vals) // We cannot use the name "Val" in this loop since there is a reference to // it in the body of the loop. @@ -346,7 +346,7 @@ void typeConflict() { *It = sizeof(Val); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Vals) + // CHECK-FIXES: for (int & Elem : Vals) // CHECK-FIXES-NEXT: Elem = sizeof(Val); typedef struct Val TD; @@ -375,7 +375,7 @@ void typeConflict() { *It = sizeof(St); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Sts) + // CHECK-FIXES: for (int & Elem : Sts) // CHECK-FIXES-NEXT: Elem = sizeof(St); } @@ -561,7 +561,7 @@ void f() { printf("I found %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Tt) + // CHECK-FIXES: for (int & Elem : Tt) // CHECK-FIXES-NEXT: printf("I found %d\n", Elem); T *Pt; @@ -569,7 +569,7 @@ void f() { printf("I found %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : *Pt) + // CHECK-FIXES: for (int & Elem : *Pt) // CHECK-FIXES-NEXT: printf("I found %d\n", Elem); S Ss; @@ -644,7 +644,7 @@ void f() { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : V) + // CHECK-FIXES: for (int & Elem : V) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); for (dependent::iterator It(V.begin()); @@ -652,7 +652,7 @@ void f() { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : V) + // CHECK-FIXES: for (int & Elem : V) // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); doublyDependent intmap; @@ -716,7 +716,7 @@ void messing_with_macros() { printf("Value: %d\n", Arr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: printf("Value: %d\n", Elem); for (int I = 0; I < N; ++I) { @@ -729,7 +729,7 @@ void messing_with_macros() { THREE_PARAM(Arr[I], Arr[I], Arr[I]); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: TWO_PARAM(Elem, Elem); // CHECK-FIXES-NEXT: THREE_PARAM(Elem, Elem, Elem); } @@ -770,13 +770,13 @@ void capturesIndex() { for (int I = 0; I < N; ++I) auto F1 = [Arr, I]() { int R1 = Arr[I] + 1; }; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: auto F1 = [Arr, &Elem]() { int R1 = Elem + 1; }; for (int I = 0; I < N; ++I) auto F2 = [Arr, &I]() { int R2 = Arr[I] + 3; }; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: auto F2 = [Arr, &Elem]() { int R2 = Elem + 3; }; // FIXME: alias don't work if the index is captured. @@ -784,28 +784,28 @@ void capturesIndex() { for (int I = 0; I < N; ++I) auto F3 = [&Arr, I]() { int R3 = Arr[I]; }; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: auto F3 = [&Arr, &Elem]() { int R3 = Elem; }; for (int I = 0; I < N; ++I) auto F4 = [&Arr, &I]() { int R4 = Arr[I]; }; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: auto F4 = [&Arr, &Elem]() { int R4 = Elem; }; // Alias declared inside lambda (by reference). for (int I = 0; I < N; ++I) auto F5 = [&Arr, I]() { int &R5 = Arr[I]; }; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: auto F5 = [&Arr, &Elem]() { int &R5 = Elem; }; for (int I = 0; I < N; ++I) auto F6 = [&Arr, &I]() { int &R6 = Arr[I]; }; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: auto F6 = [&Arr, &Elem]() { int &R6 = Elem; }; for (int I = 0; I < N; ++I) { @@ -815,7 +815,7 @@ void capturesIndex() { F(Arr[I]); } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: auto F = [Arr, &Elem](int k) // CHECK-FIXES-NEXT: printf("%d\n", Elem + k); // CHECK-FIXES: F(Elem); @@ -847,7 +847,7 @@ void implicitCapture() { }; } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: auto G3 = [&]() // CHECK-FIXES-NEXT: int R3 = Elem; // CHECK-FIXES-NEXT: int J3 = Elem + R3; @@ -858,7 +858,7 @@ void implicitCapture() { }; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: auto G4 = [=]() // CHECK-FIXES-NEXT: int R4 = Elem + 5; @@ -870,7 +870,7 @@ void implicitCapture() { }; } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto R5 : Arr) + // CHECK-FIXES: for (int R5 : Arr) // CHECK-FIXES-NEXT: auto G5 = [&]() // CHECK-FIXES-NEXT: int J5 = 8 + R5; @@ -882,7 +882,7 @@ void implicitCapture() { }; } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & R6 : Arr) + // CHECK-FIXES: for (int & R6 : Arr) // CHECK-FIXES-NEXT: auto G6 = [&]() // CHECK-FIXES-NEXT: int J6 = -1 + R6; } @@ -893,13 +893,13 @@ void iterators() { for (dependent::iterator I = Dep.begin(), E = Dep.end(); I != E; ++I) auto H1 = [&I]() { int R = *I; }; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Dep) + // CHECK-FIXES: for (int & Elem : Dep) // CHECK-FIXES-NEXT: auto H1 = [&Elem]() { int R = Elem; }; for (dependent::iterator I = Dep.begin(), E = Dep.end(); I != E; ++I) auto H2 = [&]() { int R = *I + 2; }; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Dep) + // CHECK-FIXES: for (int & Elem : Dep) // CHECK-FIXES-NEXT: auto H2 = [&]() { int R = Elem + 2; }; // FIXME: It doesn't work with const iterators. @@ -929,14 +929,14 @@ void captureByValue() { auto C1 = [&Arr, I]() { if (Arr[I] == 1); }; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES: for (int & Elem : Arr) // CHECK-FIXES-NEXT: auto C1 = [&Arr, &Elem]() { if (Elem == 1); }; for (unsigned I = 0; I < Dep.size(); ++I) { auto C2 = [&Dep, I]() { if (Dep[I] == 2); }; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Dep) + // CHECK-FIXES: for (int & Elem : Dep) // CHECK-FIXES-NEXT: auto C2 = [&Dep, &Elem]() { if (Elem == 2); }; } @@ -962,7 +962,7 @@ void f() { E Ee{ { { g( { Array[I] } ) } } }; } // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Elem : Array) + // CHECK-FIXES: for (int & Elem : Array) // CHECK-FIXES-NEXT: int A{ Elem }; // CHECK-FIXES-NEXT: int B{ g(Elem) }; // CHECK-FIXES-NEXT: int C{ g( { Elem } ) }; diff --git a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-lowercase.cpp b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-lowercase.cpp index 2d99ebb713a3..e38006e4504d 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-lowercase.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-lowercase.cpp @@ -14,21 +14,21 @@ void naming() { printf("%d\n", arr[i]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert] - // CHECK-FIXES: for (auto & elem : arr) + // CHECK-FIXES: for (int & elem : arr) // 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 - // CHECK-FIXES: for (auto & num : nums) + // CHECK-FIXES: for (int & num : nums) // CHECK-FIXES-NEXT: printf("%d\n", num); for (int i = 0; i < n; ++i) { printf("%d\n", nums_[i]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & num : nums_) + // CHECK-FIXES: for (int & num : nums_) // CHECK-FIXES-NEXT: printf("%d\n", num); int num = 0; @@ -36,7 +36,7 @@ void naming() { printf("%d\n", nums[i] + num); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : nums) + // CHECK-FIXES: for (int & elem : nums) // CHECK-FIXES-NEXT: printf("%d\n", elem + num); int elem = 0; @@ -44,7 +44,7 @@ void naming() { printf("%d\n", nums[i] + num + elem); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & nums_i : nums) + // CHECK-FIXES: for (int & nums_i : nums) // CHECK-FIXES-NEXT: printf("%d\n", nums_i + num + elem); int nums_i = 0; @@ -52,7 +52,7 @@ void naming() { printf("%d\n", nums[i] + num + elem + nums_i); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & nums_elem : nums) + // CHECK-FIXES: for (int & nums_elem : nums) // CHECK-FIXES-NEXT: printf("%d\n", nums_elem + num + elem + nums_i); int nums_elem = 0; @@ -60,7 +60,7 @@ void naming() { 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 (auto & give_me_name_0 : nums) + // 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; @@ -68,7 +68,7 @@ void naming() { 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 (auto & give_me_name_1 : nums) + // 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; @@ -79,7 +79,7 @@ void naming() { } // 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 (auto & give_me_name_0 : nums) - // CHECK-FIXES: for (auto & give_me_name_1 : nums) + // 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); } diff --git a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-uppercase.cpp b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-uppercase.cpp index 5edbe08ffa02..c82807695644 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-uppercase.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-uppercase.cpp @@ -14,21 +14,21 @@ void naming() { printf("%d\n", ARR[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert] - // CHECK-FIXES: for (auto & ELEM : ARR) + // CHECK-FIXES: for (int & ELEM : ARR) // 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 - // CHECK-FIXES: for (auto & NUM : NUMS) + // CHECK-FIXES: for (int & NUM : NUMS) // CHECK-FIXES-NEXT: printf("%d\n", NUM); for (int I = 0; I < N; ++I) { printf("%d\n", NUMS_[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & NUM : NUMS_) + // CHECK-FIXES: for (int & NUM : NUMS_) // CHECK-FIXES-NEXT: printf("%d\n", NUM); int NUM = 0; @@ -36,7 +36,7 @@ void naming() { printf("%d\n", NUMS[I] + NUM); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & ELEM : NUMS) + // CHECK-FIXES: for (int & ELEM : NUMS) // CHECK-FIXES-NEXT: printf("%d\n", ELEM + NUM); int ELEM = 0; @@ -44,7 +44,7 @@ void naming() { printf("%d\n", NUMS[I] + NUM + ELEM); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & NUMS_I : NUMS) + // CHECK-FIXES: for (int & NUMS_I : NUMS) // CHECK-FIXES-NEXT: printf("%d\n", NUMS_I + NUM + ELEM); int NUMS_I = 0; @@ -52,7 +52,7 @@ void naming() { printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & NUMS_ELEM : NUMS) + // CHECK-FIXES: for (int & NUMS_ELEM : NUMS) // CHECK-FIXES-NEXT: printf("%d\n", NUMS_ELEM + NUM + ELEM + NUMS_I); int NUMS_ELEM = 0; @@ -60,7 +60,7 @@ void naming() { 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 (auto & GIVE_ME_NAME_0 : NUMS) + // 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; @@ -68,7 +68,7 @@ void naming() { 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 (auto & GIVE_ME_NAME_1 : NUMS) + // 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; @@ -79,7 +79,7 @@ void naming() { } // 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 (auto & GIVE_ME_NAME_0 : NUMS) - // CHECK-FIXES: for (auto & GIVE_ME_NAME_1 : NUMS) + // 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); }