Index: clang-tidy/modernize/LoopConvertCheck.h =================================================================== --- clang-tidy/modernize/LoopConvertCheck.h +++ clang-tidy/modernize/LoopConvertCheck.h @@ -65,6 +65,7 @@ std::unique_ptr TUInfo; Confidence::Level MinConfidence; + VariableNamer::NamingStyle NamingStyle; }; } // namespace modernize Index: clang-tidy/modernize/LoopConvertCheck.cpp =================================================================== --- clang-tidy/modernize/LoopConvertCheck.cpp +++ clang-tidy/modernize/LoopConvertCheck.cpp @@ -406,11 +406,16 @@ Options.get("MinConfidence", "reasonable")) .Case("safe", Confidence::CL_Safe) .Case("risky", Confidence::CL_Risky) - .Default(Confidence::CL_Reasonable)) {} + .Default(Confidence::CL_Reasonable)), + NamingStyle(Options.get("NamingStyle", "llvm") == "llvm" + ? VariableNamer::NS_LLVM + : VariableNamer::NS_Google) {} void LoopConvertCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { SmallVector Confs{"risky", "reasonable", "safe"}; Options.store(Opts, "MinConfidence", Confs[static_cast(MinConfidence)]); + Options.store(Opts, "NamingStyle", + NamingStyle == VariableNamer::NS_LLVM ? "llvm" : "google"); } void LoopConvertCheck::registerMatchers(MatchFinder *Finder) { @@ -462,7 +467,7 @@ } else { VariableNamer Namer(&TUInfo->getGeneratedDecls(), &TUInfo->getParentFinder().getStmtToParentStmtMap(), - Loop, IndexVar, MaybeContainer, Context); + Loop, IndexVar, MaybeContainer, Context, NamingStyle); VarName = Namer.createIndexName(); // First, replace all usages of the array subscript expression with our new // variable. Index: clang-tidy/modernize/LoopConvertUtils.h =================================================================== --- clang-tidy/modernize/LoopConvertUtils.h +++ clang-tidy/modernize/LoopConvertUtils.h @@ -414,14 +414,17 @@ /// index, if they exist. class VariableNamer { public: + // Supported naming styles. + enum NamingStyle { NS_LLVM = 0, NS_Google = 1 }; + VariableNamer(StmtGeneratedVarNameMap *GeneratedDecls, const StmtParentMap *ReverseAST, const clang::Stmt *SourceStmt, const clang::VarDecl *OldIndex, const clang::VarDecl *TheContainer, - const clang::ASTContext *Context) + const clang::ASTContext *Context, NamingStyle Style) : GeneratedDecls(GeneratedDecls), ReverseAST(ReverseAST), SourceStmt(SourceStmt), OldIndex(OldIndex), TheContainer(TheContainer), - Context(Context) {} + Context(Context), Style(Style) {} /// \brief Generate a new index name. /// @@ -441,6 +444,8 @@ // Determine whether or not a declaration that would conflict with Symbol // exists in an outer context or in any statement contained in SourceStmt. bool declarationExists(llvm::StringRef Symbol); + + NamingStyle Style; }; } // namespace modernize Index: clang-tidy/modernize/LoopConvertUtils.cpp =================================================================== --- clang-tidy/modernize/LoopConvertUtils.cpp +++ clang-tidy/modernize/LoopConvertUtils.cpp @@ -821,7 +821,7 @@ if (Len > 1 && ContainerName[Len - 1] == 's') IteratorName = ContainerName.substr(0, Len - 1); else - IteratorName = "elem"; + IteratorName = (Style == NS_LLVM ? "Elem" : "elem"); if (!declarationExists(IteratorName)) return IteratorName; @@ -838,7 +838,7 @@ if (!declarationExists(IteratorName)) return IteratorName; - IteratorName = "_elem_"; + IteratorName = (Style == NS_LLVM ? "Elem_" : "elem_"); // Someone defeated my naming scheme... while (declarationExists(IteratorName)) Index: clang-tidy/modernize/ModernizeTidyModule.cpp =================================================================== --- clang-tidy/modernize/ModernizeTidyModule.cpp +++ clang-tidy/modernize/ModernizeTidyModule.cpp @@ -41,6 +41,7 @@ ClangTidyOptions Options; auto &Opts = Options.CheckOptions; Opts["modernize-loop-convert.MinConfidence"] = "reasonable"; + Opts["modernize-loop-convert.NamingStyle"] = "llvm"; // Also: "google". Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google". Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google". Index: test/clang-tidy/modernize-loop-convert-basic.cpp =================================================================== --- test/clang-tidy/modernize-loop-convert-basic.cpp +++ test/clang-tidy/modernize-loop-convert-basic.cpp @@ -18,8 +18,8 @@ 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-NEXT: sum += elem; + // CHECK-FIXES: for (auto & Elem : arr) + // CHECK-FIXES-NEXT: sum += Elem; // CHECK-FIXES-NEXT: int k; for (int i = 0; i < N; ++i) { @@ -27,66 +27,66 @@ sum += arr[i] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : arr) - // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem); - // CHECK-FIXES-NEXT: sum += elem + 2; + // CHECK-FIXES: for (auto & Elem : arr) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); + // CHECK-FIXES-NEXT: sum += Elem + 2; for (int i = 0; i < N; ++i) { int x = arr[i]; 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-NEXT: int x = elem; - // CHECK-FIXES-NEXT: int y = elem + 2; + // CHECK-FIXES: for (auto & Elem : arr) + // CHECK-FIXES-NEXT: int x = Elem; + // CHECK-FIXES-NEXT: int y = Elem + 2; for (int i = 0; i < N; ++i) { int x = N; x = arr[i]; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : arr) + // CHECK-FIXES: for (auto & Elem : arr) // CHECK-FIXES-NEXT: int x = N; - // CHECK-FIXES-NEXT: x = elem; + // CHECK-FIXES-NEXT: x = Elem; for (int i = 0; i < N; ++i) { arr[i] += 1; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : arr) - // CHECK-FIXES-NEXT: elem += 1; + // CHECK-FIXES: for (auto & Elem : arr) + // CHECK-FIXES-NEXT: Elem += 1; for (int i = 0; i < N; ++i) { int x = arr[i] + 2; arr[i]++; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : arr) - // CHECK-FIXES-NEXT: int x = elem + 2; - // CHECK-FIXES-NEXT: elem++; + // CHECK-FIXES: for (auto & Elem : arr) + // CHECK-FIXES-NEXT: int x = Elem + 2; + // CHECK-FIXES-NEXT: Elem++; for (int i = 0; i < N; ++i) { 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-NEXT: elem = 4 + elem; + // CHECK-FIXES: for (auto & 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-NEXT: sum += elem; + // CHECK-FIXES: for (auto & Elem : arr) + // CHECK-FIXES-NEXT: sum += Elem; for (int i = 0; i < N; ++i) { printf("Fibonacci number %d has address %p\n", arr[i], &arr[i]); sum += arr[i] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : arr) - // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", elem, &elem); - // CHECK-FIXES-NEXT: sum += elem + 2; + // CHECK-FIXES: for (auto & Elem : arr) + // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", Elem, &Elem); + // CHECK-FIXES-NEXT: sum += Elem + 2; Val teas[N]; for (int i = 0; i < N; ++i) { @@ -102,8 +102,8 @@ 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 (const auto & elem : constArr) - // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", elem, elem + elem); + // CHECK-FIXES: for (const auto & Elem : constArr) + // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", Elem, Elem + Elem); } struct HasArr { @@ -114,15 +114,15 @@ printf("%d", Arr[i]); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : Arr) - // CHECK-FIXES-NEXT: printf("%d", elem); + // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES-NEXT: printf("%d", Elem); for (int i = 0; i < N; ++i) { printf("%d", ValArr[i].x); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : ValArr) - // CHECK-FIXES-NEXT: printf("%d", elem.x); + // CHECK-FIXES: for (auto & Elem : ValArr) + // CHECK-FIXES-NEXT: printf("%d", Elem.x); } void explicitThis() { @@ -130,15 +130,15 @@ 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-NEXT: printf("%d", elem); + // CHECK-FIXES: for (auto & Elem : this->Arr) + // CHECK-FIXES-NEXT: printf("%d", Elem); for (int i = 0; i < N; ++i) { printf("%d", this->ValArr[i].x); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : this->ValArr) - // CHECK-FIXES-NEXT: printf("%d", elem.x); + // CHECK-FIXES: for (auto & Elem : this->ValArr) + // CHECK-FIXES-NEXT: printf("%d", Elem.x); } }; @@ -156,8 +156,8 @@ for (int i = 0; i < N; ++i) (v.*mfpArr[i])(); // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : mfpArr) - // CHECK-FIXES-NEXT: (v.*elem)(); + // CHECK-FIXES: for (auto & Elem : mfpArr) + // CHECK-FIXES-NEXT: (v.*Elem)(); struct Foo { int (Val::*f)(); @@ -166,8 +166,8 @@ for (int i = 0; i < N; ++i) int r = (v.*(foo[i].f))(); // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : foo) - // CHECK-FIXES-NEXT: int r = (v.*(elem.f))(); + // CHECK-FIXES: for (auto & Elem : foo) + // CHECK-FIXES-NEXT: int r = (v.*(Elem.f))(); } @@ -182,24 +182,24 @@ printf("I found %d\n", *it); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : t) - // CHECK-FIXES-NEXT: printf("I found %d\n", elem); + // CHECK-FIXES: for (auto & Elem : t) + // CHECK-FIXES-NEXT: printf("I found %d\n", Elem); T *pt; for (T::iterator it = pt->begin(), e = pt->end(); it != e; ++it) { 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-NEXT: printf("I found %d\n", elem); + // CHECK-FIXES: for (auto & Elem : *pt) + // CHECK-FIXES-NEXT: printf("I found %d\n", Elem); S s; for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) { printf("s has value %d\n", (*it).x); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : s) - // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x); + // CHECK-FIXES: for (auto & Elem : s) + // CHECK-FIXES-NEXT: printf("s has value %d\n", (Elem).x); S *ps; for (S::iterator it = ps->begin(), e = ps->end(); it != e; ++it) { @@ -213,51 +213,51 @@ printf("s has value %d\n", it->x); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : s) - // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x); + // CHECK-FIXES: for (auto & Elem : s) + // CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.x); for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) { it->x = 3; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : s) - // CHECK-FIXES-NEXT: elem.x = 3; + // CHECK-FIXES: for (auto & Elem : s) + // CHECK-FIXES-NEXT: Elem.x = 3; for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) { (*it).x = 3; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : s) - // CHECK-FIXES-NEXT: (elem).x = 3; + // CHECK-FIXES: for (auto & Elem : s) + // CHECK-FIXES-NEXT: (Elem).x = 3; for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) { it->nonConstFun(4, 5); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : s) - // CHECK-FIXES-NEXT: elem.nonConstFun(4, 5); + // CHECK-FIXES: for (auto & Elem : s) + // CHECK-FIXES-NEXT: Elem.nonConstFun(4, 5); U u; for (U::iterator it = u.begin(), e = u.end(); it != e; ++it) { printf("s has value %d\n", it->x); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : u) - // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x); + // CHECK-FIXES: for (auto & Elem : u) + // CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.x); for (U::iterator it = u.begin(), e = u.end(); it != e; ++it) { printf("s has value %d\n", (*it).x); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : u) - // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x); + // CHECK-FIXES: for (auto & Elem : u) + // CHECK-FIXES-NEXT: printf("s has value %d\n", (Elem).x); U::iterator A; for (U::iterator i = u.begin(), e = u.end(); i != e; ++i) int k = A->x + i->x; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : u) - // CHECK-FIXES-NEXT: int k = A->x + elem.x; + // CHECK-FIXES: for (auto & Elem : u) + // CHECK-FIXES-NEXT: int k = A->x + Elem.x; dependent v; for (dependent::iterator it = v.begin(), e = v.end(); @@ -265,16 +265,16 @@ 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-NEXT: printf("Fibonacci number is %d\n", elem); + // CHECK-FIXES: for (auto & Elem : v) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); for (dependent::iterator it(v.begin()), e = v.end(); it != e; ++it) { 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-NEXT: printf("Fibonacci number is %d\n", elem); + // CHECK-FIXES: for (auto & Elem : v) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); doublyDependent intmap; for (doublyDependent::iterator it = intmap.begin(), e = intmap.end(); @@ -282,8 +282,8 @@ printf("intmap[%d] = %d", it->first, it->second); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : intmap) - // CHECK-FIXES: printf("intmap[%d] = %d", elem.first, elem.second); + // CHECK-FIXES: for (auto & Elem : intmap) + // CHECK-FIXES: printf("intmap[%d] = %d", Elem.first, Elem.second); // PtrSet's iterator dereferences by value so auto & can't be used. { @@ -333,8 +333,8 @@ printf("s has value %d\n", (*it).x); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & elem : s) - // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x); + // CHECK-FIXES: for (const auto & Elem : s) + // CHECK-FIXES-NEXT: printf("s has value %d\n", (Elem).x); S *ps; for (S::const_iterator it = ps->begin(), e = ps->end(); it != e; ++it) { @@ -379,12 +379,12 @@ for (iterator I = begin(), E = end(); I != E; ++I) (void) *I; // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : *this) + // CHECK-FIXES: for (auto & Elem : *this) for (iterator I = C::begin(), E = C::end(); I != E; ++I) (void) *I; // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : *this) + // CHECK-FIXES: for (auto & Elem : *this) for (iterator I = begin(), E = end(); I != E; ++I) { (void) *I; @@ -394,7 +394,7 @@ for (iterator I = begin(); I != end(); ++I) (void) *I; // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : *this) + // CHECK-FIXES: for (auto & Elem : *this) for (iterator I = begin(); I != end(); ++I) { (void) *I; @@ -406,12 +406,12 @@ for (const_iterator I = begin(), E = end(); I != E; ++I) (void) *I; // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & elem : *this) + // CHECK-FIXES: for (const auto & Elem : *this) for (const_iterator I = C::begin(), E = C::end(); I != E; ++I) (void) *I; // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & elem : *this) + // CHECK-FIXES: for (const auto & Elem : *this) for (const_iterator I = begin(), E = end(); I != E; ++I) { (void) *I; @@ -433,7 +433,7 @@ for (iterator I = begin(), E = end(); I != E; ++I) (void) *I; // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : *this) + // CHECK-FIXES: for (auto & Elem : *this) } }; @@ -456,27 +456,27 @@ sum += v[i] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : v) - // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem); - // CHECK-FIXES-NEXT: sum += elem + 2; + // CHECK-FIXES: for (auto & Elem : v) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); + // CHECK-FIXES-NEXT: sum += Elem + 2; for (int i = 0, e = v.size(); i < e; ++i) { printf("Fibonacci number is %d\n", v.at(i)); 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-NEXT: printf("Fibonacci number is %d\n", elem); - // CHECK-FIXES-NEXT: sum += elem + 2; + // CHECK-FIXES: for (auto & Elem : v) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); + // CHECK-FIXES-NEXT: sum += Elem + 2; for (int i = 0, e = pv->size(); i < e; ++i) { printf("Fibonacci number is %d\n", pv->at(i)); 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-NEXT: printf("Fibonacci number is %d\n", elem); - // CHECK-FIXES-NEXT: sum += elem + 2; + // CHECK-FIXES: for (auto & Elem : *pv) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); + // CHECK-FIXES-NEXT: sum += Elem + 2; // This test will fail if size() isn't called repeatedly, since it // returns unsigned int, and 0 is deduced to be signed int. @@ -487,18 +487,18 @@ sum += (*pv)[i] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : *pv) - // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem); - // CHECK-FIXES-NEXT: sum += elem + 2; + // CHECK-FIXES: for (auto & Elem : *pv) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); + // CHECK-FIXES-NEXT: sum += Elem + 2; for (int i = 0; i < cv->size(); ++i) { printf("Fibonacci number is %d\n", cv->at(i)); 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-NEXT: printf("Fibonacci number is %d\n", elem); - // CHECK-FIXES-NEXT: sum += elem + 2; + // CHECK-FIXES: for (auto & Elem : *cv) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); + // CHECK-FIXES-NEXT: sum += Elem + 2; } void constness() { @@ -508,27 +508,27 @@ sum += constv[i] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & elem : constv) - // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem); - // CHECK-FIXES-NEXT: sum += elem + 2; + // CHECK-FIXES: for (const auto & Elem : constv) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); + // CHECK-FIXES-NEXT: sum += Elem + 2; for (int i = 0, e = constv.size(); i < e; ++i) { printf("Fibonacci number is %d\n", constv.at(i)); sum += constv.at(i) + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & elem : constv) - // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem); - // CHECK-FIXES-NEXT: sum += elem + 2; + // CHECK-FIXES: for (const auto & Elem : constv) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); + // CHECK-FIXES-NEXT: sum += Elem + 2; for (int i = 0, e = pconstv->size(); i < e; ++i) { printf("Fibonacci number is %d\n", pconstv->at(i)); sum += pconstv->at(i) + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & elem : *pconstv) - // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem); - // CHECK-FIXES-NEXT: sum += elem + 2; + // CHECK-FIXES: for (const auto & Elem : *pconstv) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); + // CHECK-FIXES-NEXT: sum += Elem + 2; // This test will fail if size() isn't called repeatedly, since it // returns unsigned int, and 0 is deduced to be signed int. @@ -539,9 +539,9 @@ sum += (*pconstv)[i] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & elem : *pconstv) - // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", elem); - // CHECK-FIXES-NEXT: sum += elem + 2; + // CHECK-FIXES: for (const auto & Elem : *pconstv) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); + // CHECK-FIXES-NEXT: sum += Elem + 2; } // Check for loops that don't mention containers. @@ -592,15 +592,15 @@ 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-NEXT: printf("%d\n", elem); + // CHECK-FIXES: for (auto & 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 (const auto & elem : const_CBE) - // CHECK-FIXES-NEXT: printf("%d\n", elem); + // CHECK-FIXES: for (const auto & Elem : const_CBE) + // CHECK-FIXES-NEXT: printf("%d\n", Elem); } struct DerefByValue { @@ -618,17 +618,17 @@ 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-NEXT: printf("%d\n", elem); + // CHECK-FIXES: for (auto Elem : DBV) + // CHECK-FIXES-NEXT: printf("%d\n", Elem); for (unsigned i = 0, e = DBV.size(); i < e; ++i) { auto f = [DBV, i]() {}; 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-NEXT: auto f = [DBV, &elem]() {}; - // CHECK-FIXES-NEXT: printf("%d\n", elem); + // CHECK-FIXES: for (auto Elem : DBV) + // CHECK-FIXES-NEXT: auto f = [DBV, &Elem]() {}; + // CHECK-FIXES-NEXT: printf("%d\n", Elem); } } // namespace PseudoArray Index: test/clang-tidy/modernize-loop-convert-extra.cpp =================================================================== --- test/clang-tidy/modernize-loop-convert-extra.cpp +++ test/clang-tidy/modernize-loop-convert-extra.cpp @@ -14,9 +14,9 @@ int b = arr[i][a]; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : arr) + // CHECK-FIXES: for (auto & Elem : arr) // CHECK-FIXES-NEXT: int a = 0; - // CHECK-FIXES-NEXT: int b = elem[a]; + // CHECK-FIXES-NEXT: int b = Elem[a]; for (int j = 0; j < M; ++j) { int a = 0; @@ -64,10 +64,10 @@ int z = Arr[i].x + t.x; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : Arr) - // CHECK-FIXES-NEXT: Val &t = elem; + // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES-NEXT: Val &t = Elem; // CHECK-FIXES-NEXT: int y = t.x; - // CHECK-FIXES-NEXT: int z = elem.x + t.x; + // CHECK-FIXES-NEXT: int z = Elem.x + t.x; for (int i = 0; i < N; ++i) { Val t = Arr[i]; @@ -75,10 +75,10 @@ int z = Arr[i].x + t.x; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : Arr) - // CHECK-FIXES-NEXT: Val t = elem; + // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES-NEXT: Val t = Elem; // CHECK-FIXES-NEXT: int y = t.x; - // CHECK-FIXES-NEXT: int z = elem.x + t.x; + // CHECK-FIXES-NEXT: int z = Elem.x + t.x; // The same for pseudo-arrays like std::vector (or here dependent) // which provide a subscript operator[]. @@ -108,8 +108,8 @@ int y = t.x; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : Arr) - // CHECK-FIXES-NEXT: Val &t = func(elem); + // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES-NEXT: Val &t = func(Elem); // CHECK-FIXES-NEXT: int y = t.x; int IntArr[N]; @@ -164,8 +164,8 @@ IntRef Int(IntArr[i]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : IntArr) - // CHECK-FIXES-NEXT: IntRef Int(elem); + // CHECK-FIXES: for (auto & Elem : IntArr) + // CHECK-FIXES-NEXT: IntRef Int(Elem); } @@ -218,8 +218,8 @@ unsigned othersize = other.size(); } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : dep) - // CHECK-FIXES-NEXT: printf("%d\n", elem); + // CHECK-FIXES: for (auto & Elem : dep) + // CHECK-FIXES-NEXT: printf("%d\n", Elem); // CHECK-FIXES-NEXT: const int& idx = other[0]; // CHECK-FIXES-NEXT: unsigned othersize = other.size(); @@ -418,10 +418,10 @@ } // 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-FIXES: for (auto & elem : Arr) + // CHECK-FIXES: for (auto & Elem : Arr) // CHECK-FIXES-NEXT: for (auto & Arr_j : Arr) - // CHECK-FIXES-NEXT: int k = elem.x + Arr_j.x; - // CHECK-FIXES-NOT: int l = elem.x + elem.x; + // CHECK-FIXES-NEXT: int k = Elem.x + Arr_j.x; + // CHECK-FIXES-NOT: int l = Elem.x + Elem.x; // The inner loop is also convertible, but doesn't need to be converted // immediately. FIXME: update this test when that changes. @@ -432,9 +432,9 @@ } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : Nest) + // CHECK-FIXES: for (auto & Elem : Nest) // 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", Elem[j].x); // Note that the order of M and N are switched for this test. for (int j = 0; j < M; ++j) { @@ -445,8 +445,8 @@ // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop instead // CHECK-FIXES-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[i]) // CHECK-FIXES: for (int j = 0; j < M; ++j) - // CHECK-FIXES-NEXT: for (auto & elem : Nest) - // CHECK-FIXES-NEXT: printf("Got item %d", elem[j].x); + // CHECK-FIXES-NEXT: for (auto & Elem : Nest) + // CHECK-FIXES-NEXT: printf("Got item %d", Elem[j].x); // The inner loop is also convertible. Nested NestT; @@ -456,8 +456,8 @@ } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : NestT) - // CHECK-FIXES-NEXT: for (T::iterator TI = (elem).begin(), TE = (elem).end(); TI != TE; ++TI) + // CHECK-FIXES: for (auto & Elem : NestT) + // CHECK-FIXES-NEXT: for (T::iterator TI = (Elem).begin(), TE = (Elem).end(); TI != TE; ++TI) // CHECK-FIXES-NEXT: printf("%d", *TI); // The inner loop is also convertible. @@ -468,8 +468,8 @@ } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & elem : NestS) - // CHECK-FIXES-NEXT: for (S::const_iterator SI = (elem).begin(), SE = (elem).end(); SI != SE; ++SI) + // CHECK-FIXES: for (const auto & Elem : NestS) + // CHECK-FIXES-NEXT: for (S::const_iterator SI = (Elem).begin(), SE = (Elem).end(); SI != SE; ++SI) // CHECK-FIXES-NEXT: printf("%d", *SI); for (Nested::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) { @@ -528,9 +528,9 @@ MutableVal j = *i; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : exes[index].getS()) - // CHECK-FIXES-NEXT: MutableVal k = elem; - // CHECK-FIXES-NEXT: MutableVal j = elem; + // CHECK-FIXES: for (auto & Elem : exes[index].getS()) + // CHECK-FIXES-NEXT: MutableVal k = Elem; + // CHECK-FIXES-NEXT: MutableVal j = Elem; } void f() { @@ -540,24 +540,24 @@ printf("I found %d\n", *it); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : t) - // CHECK-FIXES-NEXT: printf("I found %d\n", elem); + // CHECK-FIXES: for (auto & Elem : t) + // CHECK-FIXES-NEXT: printf("I found %d\n", Elem); T *pt; for (T::iterator it = pt->begin(); it != pt->end(); ++it) { 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-NEXT: printf("I found %d\n", elem); + // CHECK-FIXES: for (auto & Elem : *pt) + // CHECK-FIXES-NEXT: printf("I found %d\n", Elem); S s; for (S::iterator it = s.begin(); it != s.end(); ++it) { printf("s has value %d\n", (*it).x); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : s) - // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x); + // CHECK-FIXES: for (auto & Elem : s) + // CHECK-FIXES-NEXT: printf("s has value %d\n", (Elem).x); S *ps; for (S::iterator it = ps->begin(); it != ps->end(); ++it) { @@ -571,51 +571,51 @@ printf("s has value %d\n", it->x); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : s) - // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x); + // CHECK-FIXES: for (auto & Elem : s) + // CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.x); for (S::iterator it = s.begin(); it != s.end(); ++it) { it->x = 3; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : s) - // CHECK-FIXES-NEXT: elem.x = 3; + // CHECK-FIXES: for (auto & Elem : s) + // CHECK-FIXES-NEXT: Elem.x = 3; for (S::iterator it = s.begin(); it != s.end(); ++it) { (*it).x = 3; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : s) - // CHECK-FIXES-NEXT: (elem).x = 3; + // CHECK-FIXES: for (auto & Elem : s) + // CHECK-FIXES-NEXT: (Elem).x = 3; for (S::iterator it = s.begin(); it != s.end(); ++it) { it->nonConstFun(4, 5); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : s) - // CHECK-FIXES-NEXT: elem.nonConstFun(4, 5); + // CHECK-FIXES: for (auto & Elem : s) + // CHECK-FIXES-NEXT: Elem.nonConstFun(4, 5); U u; for (U::iterator it = u.begin(); it != u.end(); ++it) { printf("s has value %d\n", it->x); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : u) - // CHECK-FIXES-NEXT: printf("s has value %d\n", elem.x); + // CHECK-FIXES: for (auto & Elem : u) + // CHECK-FIXES-NEXT: printf("s has value %d\n", Elem.x); for (U::iterator it = u.begin(); it != u.end(); ++it) { printf("s has value %d\n", (*it).x); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : u) - // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x); + // CHECK-FIXES: for (auto & Elem : u) + // CHECK-FIXES-NEXT: printf("s has value %d\n", (Elem).x); U::iterator A; for (U::iterator i = u.begin(); i != u.end(); ++i) int k = A->x + i->x; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : u) - // CHECK-FIXES-NEXT: int k = A->x + elem.x; + // CHECK-FIXES: for (auto & Elem : u) + // CHECK-FIXES-NEXT: int k = A->x + Elem.x; dependent v; for (dependent::iterator it = v.begin(); @@ -623,16 +623,16 @@ 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-NEXT: printf("Fibonacci number is %d\n", elem); + // CHECK-FIXES: for (auto & Elem : v) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); for (dependent::iterator it(v.begin()); it != v.end(); ++it) { 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-NEXT: printf("Fibonacci number is %d\n", elem); + // CHECK-FIXES: for (auto & Elem : v) + // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", Elem); doublyDependent intmap; for (doublyDependent::iterator it = intmap.begin(); @@ -640,8 +640,8 @@ printf("intmap[%d] = %d", it->first, it->second); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : intmap) - // CHECK-FIXES-NEXT: printf("intmap[%d] = %d", elem.first, elem.second); + // CHECK-FIXES: for (auto & Elem : intmap) + // CHECK-FIXES-NEXT: printf("intmap[%d] = %d", Elem.first, Elem.second); } void different_type() { @@ -655,8 +655,8 @@ printf("s has value %d\n", (*it).x); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & elem : s) - // CHECK-FIXES-NEXT: printf("s has value %d\n", (elem).x); + // CHECK-FIXES: for (const auto & Elem : s) + // CHECK-FIXES-NEXT: printf("s has value %d\n", (Elem).x); S *ps; for (S::const_iterator it = ps->begin(); it != ps->end(); ++it) { @@ -695,8 +695,8 @@ 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-NEXT: printf("Value: %d\n", elem); + // CHECK-FIXES: for (auto & Elem : arr) + // CHECK-FIXES-NEXT: printf("Value: %d\n", Elem); for (int i = 0; i < N; ++i) { printf("Value: %d\n", CONT arr[i]); @@ -708,9 +708,9 @@ 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-NEXT: TWO_PARAM(elem, elem); - // CHECK-FIXES-NEXT: THREE_PARAM(elem, elem, elem); + // CHECK-FIXES: for (auto & Elem : arr) + // CHECK-FIXES-NEXT: TWO_PARAM(Elem, Elem); + // CHECK-FIXES-NEXT: THREE_PARAM(Elem, Elem, Elem); } } // namespace Macros @@ -728,7 +728,7 @@ for (S::iterator SI = s.begin(), SE = s.end(); SI != SE; ++SI) (void) *SI; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : s) + // CHECK-FIXES: for (auto & Elem : s) } void template_instantiation() { @@ -749,43 +749,43 @@ 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-NEXT: auto F1 = [Arr, &elem]() { int R1 = elem + 1; }; + // CHECK-FIXES: for (auto & 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-NEXT: auto F2 = [Arr, &elem]() { int R2 = elem + 3; }; + // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES-NEXT: auto F2 = [Arr, &Elem]() { int R2 = Elem + 3; }; // FIXME: alias don't work if the index is captured. // Alias declared inside lambda (by value). 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-NEXT: auto F3 = [&Arr, &elem]() { int R3 = elem; }; + // CHECK-FIXES: for (auto & 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-NEXT: auto F4 = [&Arr, &elem]() { int R4 = elem; }; + // CHECK-FIXES: for (auto & 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-NEXT: auto F5 = [&Arr, &elem]() { int &R5 = elem; }; + // CHECK-FIXES: for (auto & 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-NEXT: auto F6 = [&Arr, &elem]() { int &R6 = elem; }; + // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES-NEXT: auto F6 = [&Arr, &Elem]() { int &R6 = Elem; }; for (int I = 0; I < N; ++I) { auto F = [Arr, I](int k) { @@ -794,10 +794,10 @@ F(Arr[I]); } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : Arr) - // CHECK-FIXES-NEXT: auto F = [Arr, &elem](int k) - // CHECK-FIXES-NEXT: printf("%d\n", elem + k); - // CHECK-FIXES: F(elem); + // CHECK-FIXES: for (auto & Elem : Arr) + // CHECK-FIXES-NEXT: auto F = [Arr, &Elem](int k) + // CHECK-FIXES-NEXT: printf("%d\n", Elem + k); + // CHECK-FIXES: F(Elem); } void implicitCapture() { @@ -826,10 +826,10 @@ }; } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : Arr) + // CHECK-FIXES: for (auto & Elem : Arr) // CHECK-FIXES-NEXT: auto G3 = [&]() - // CHECK-FIXES-NEXT: int R3 = elem; - // CHECK-FIXES-NEXT: int J3 = elem + R3; + // CHECK-FIXES-NEXT: int R3 = Elem; + // CHECK-FIXES-NEXT: int J3 = Elem + R3; for (int I = 0; I < N; ++I) { auto G4 = [=]() { @@ -837,9 +837,9 @@ }; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & elem : Arr) + // CHECK-FIXES: for (auto & Elem : Arr) // CHECK-FIXES-NEXT: auto G4 = [=]() - // CHECK-FIXES-NEXT: int R4 = elem + 5; + // CHECK-FIXES-NEXT: int R4 = Elem + 5; // Alias by value. for (int I = 0; I < N; ++I) { @@ -872,14 +872,14 @@ 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-NEXT: auto H1 = [&elem]() { int R = elem; }; + // CHECK-FIXES: for (auto & 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-NEXT: auto H2 = [&]() { int R = elem + 2; }; + // CHECK-FIXES: for (auto & Elem : dep) + // CHECK-FIXES-NEXT: auto H2 = [&]() { int R = Elem + 2; }; // FIXME: It doesn't work with const iterators. for (dependent::const_iterator I = dep.begin(), E = dep.end(); @@ -908,15 +908,15 @@ 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-NEXT: auto C1 = [&Arr, &elem]() { if (elem == 1); }; + // CHECK-FIXES: for (auto & 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-NEXT: auto C2 = [&Dep, &elem]() { if (elem == 2); }; + // CHECK-FIXES: for (auto & Elem : Dep) + // CHECK-FIXES-NEXT: auto C2 = [&Dep, &Elem]() { if (Elem == 2); }; } } // namespace Lambdas @@ -941,11 +941,11 @@ E e{ { { g( { Array[i] } ) } } }; } // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead - // CHECK-FIXES: int a{ elem }; - // CHECK-FIXES-NEXT: int b{ g(elem) }; - // CHECK-FIXES-NEXT: int c{ g( { elem } ) }; - // CHECK-FIXES-NEXT: D d{ { g( { elem } ) } }; - // CHECK-FIXES-NEXT: E e{ { { g( { elem } ) } } }; + // CHECK-FIXES: int a{ Elem }; + // CHECK-FIXES-NEXT: int b{ g(Elem) }; + // CHECK-FIXES-NEXT: int c{ g( { Elem } ) }; + // CHECK-FIXES-NEXT: D d{ { g( { Elem } ) } }; + // CHECK-FIXES-NEXT: E e{ { { g( { Elem } ) } } }; } } // namespace InitLists