Skip to content

Commit 06d010c

Browse files
committedAug 25, 2015
Avoid LoopConvertCheck replacements in template instantiations.
Summary: Prevent LoopConvertCheck from doing replacements in template instantiations, and add a test. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D12321 llvm-svn: 245942
1 parent d3ef108 commit 06d010c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

‎clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ StatementMatcher makeArrayLoopMatcher() {
7070
expr(hasType(isInteger())).bind(ConditionBoundName);
7171

7272
return forStmt(
73+
unless(isInTemplateInstantiation()),
7374
hasLoopInit(declStmt(hasSingleDecl(InitToZeroMatcher))),
7475
hasCondition(anyOf(
7576
binaryOperator(hasOperatorName("<"),
@@ -159,6 +160,7 @@ StatementMatcher makeIteratorLoopMatcher() {
159160
.bind(DerefByRefResultName)))))));
160161

161162
return forStmt(
163+
unless(isInTemplateInstantiation()),
162164
hasLoopInit(anyOf(declStmt(declCountIs(2),
163165
containsDeclaration(0, InitDeclMatcher),
164166
containsDeclaration(1, EndDeclMatcher)),
@@ -258,6 +260,7 @@ StatementMatcher makePseudoArrayLoopMatcher() {
258260
EndInitMatcher));
259261

260262
return forStmt(
263+
unless(isInTemplateInstantiation()),
261264
hasLoopInit(
262265
anyOf(declStmt(declCountIs(2),
263266
containsDeclaration(0, InitToZeroMatcher),

‎clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,24 @@ void messing_with_macros() {
626626
}
627627

628628
} // namespace Macros
629+
630+
namespace Templates {
631+
632+
template <class Container>
633+
void set_union(Container &container) {
634+
for (typename Container::const_iterator SI = container.begin(),
635+
SE = container.end(); SI != SE; ++SI) {
636+
}
637+
S s;
638+
for (S::iterator SI = s.begin(), SE = s.end(); SI != SE; ++SI) {
639+
}
640+
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
641+
// CHECK-FIXES: for (auto & elem : s) {
642+
}
643+
644+
void template_instantiation() {
645+
S a;
646+
set_union(a);
647+
}
648+
649+
} // namespace Templates

0 commit comments

Comments
 (0)
Please sign in to comment.