diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp index f3dd15439d82..420317e10177 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp @@ -70,6 +70,7 @@ StatementMatcher makeArrayLoopMatcher() { expr(hasType(isInteger())).bind(ConditionBoundName); return forStmt( + unless(isInTemplateInstantiation()), hasLoopInit(declStmt(hasSingleDecl(InitToZeroMatcher))), hasCondition(anyOf( binaryOperator(hasOperatorName("<"), @@ -159,6 +160,7 @@ StatementMatcher makeIteratorLoopMatcher() { .bind(DerefByRefResultName))))))); return forStmt( + unless(isInTemplateInstantiation()), hasLoopInit(anyOf(declStmt(declCountIs(2), containsDeclaration(0, InitDeclMatcher), containsDeclaration(1, EndDeclMatcher)), @@ -258,6 +260,7 @@ StatementMatcher makePseudoArrayLoopMatcher() { EndInitMatcher)); return forStmt( + unless(isInTemplateInstantiation()), hasLoopInit( anyOf(declStmt(declCountIs(2), containsDeclaration(0, InitToZeroMatcher), 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 74cfb327f0e8..6bcb931e8cf6 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 @@ -626,3 +626,24 @@ void messing_with_macros() { } } // 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