diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp @@ -128,10 +128,7 @@ .bind(BeginCallName); DeclarationMatcher InitDeclMatcher = - varDecl(hasInitializer(anyOf(ignoringParenImpCasts(BeginCallMatcher), - materializeTemporaryExpr( - ignoringParenImpCasts(BeginCallMatcher)), - hasDescendant(BeginCallMatcher)))) + varDecl(hasInitializer(hasDescendant(BeginCallMatcher))) .bind(InitVarName); DeclarationMatcher EndDeclMatcher = @@ -791,11 +788,6 @@ CanonicalBeginType->getPointeeType(), CanonicalInitVarType->getPointeeType())) return false; - } else if (!Context->hasSameType(CanonicalInitVarType, - CanonicalBeginType)) { - // Check for qualified types to avoid conversions from non-const to const - // iterator types. - return false; } } else if (FixerKind == LFK_PseudoArray) { // This call is required to obtain the container. 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 --- a/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp @@ -270,6 +270,13 @@ // CHECK-FIXES: for (auto & P : *Ps) // CHECK-FIXES-NEXT: printf("s has value %d\n", P.X); + for (S::const_iterator It = Ss.begin(), E = Ss.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 It : Ss) + // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); + for (S::const_iterator It = Ss.cbegin(), E = Ss.cend(); It != E; ++It) { printf("s has value %d\n", (*It).X); }