[PATCH] D12321: Avoid LoopConvertCheck replacements in template instantiations.
Angel Garcia via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 25 08:19:56 PDT 2015
angelgarcia updated this revision to Diff 33081.
angelgarcia added a comment.
Add test.
http://reviews.llvm.org/D12321
Files:
clang-tidy/modernize/LoopConvertCheck.cpp
test/clang-tidy/modernize-loop-convert-extra.cpp
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 <class Container>
+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
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),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12321.33081.patch
Type: text/x-patch
Size: 1962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150825/cd588c37/attachment.bin>
More information about the cfe-commits
mailing list