Index: clang-tidy/modernize/LoopConvertCheck.cpp =================================================================== --- clang-tidy/modernize/LoopConvertCheck.cpp +++ clang-tidy/modernize/LoopConvertCheck.cpp @@ -70,6 +70,7 @@ expr(hasType(isInteger())).bind(ConditionBoundName); return forStmt( + unless(isInTemplateInstantiation()), hasLoopInit(declStmt(hasSingleDecl(InitToZeroMatcher))), hasCondition(anyOf( binaryOperator(hasOperatorName("<"), @@ -159,6 +160,7 @@ .bind(DerefByRefResultName))))))); return forStmt( + unless(isInTemplateInstantiation()), hasLoopInit(anyOf(declStmt(declCountIs(2), containsDeclaration(0, InitDeclMatcher), containsDeclaration(1, EndDeclMatcher)), @@ -258,6 +260,7 @@ EndInitMatcher)); return forStmt( + unless(isInTemplateInstantiation()), hasLoopInit( anyOf(declStmt(declCountIs(2), containsDeclaration(0, InitToZeroMatcher), 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 @@ -626,3 +626,24 @@ } } // namespace Macros + +namespace Templates { + +template +void set_union(Container &container) { + for (typename Container::const_iterator SI = container.begin(), + SE = container.end(); SI != SE; ++SI) { + } + S s; + for (S::iterator SI = s.begin(), SE = s.end(); SI != SE; ++SI) { + } + // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead + // CHECK-FIXES: for (auto & elem : s) { +} + +void template_instantiation() { + S a; + set_union(a); +} + +} // namespace Templates