[clang-tools-extra] r245942 - Avoid LoopConvertCheck replacements in template instantiations.

Angel Garcia Gomez via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 25 08:44:01 PDT 2015


Author: angelgarcia
Date: Tue Aug 25 10:44:00 2015
New Revision: 245942

URL: http://llvm.org/viewvc/llvm-project?rev=245942&view=rev
Log:
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

Modified:
    clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp?rev=245942&r1=245941&r2=245942&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Tue Aug 25 10:44:00 2015
@@ -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 makePseudoArrayLoopMatc
                  EndInitMatcher));
 
   return forStmt(
+             unless(isInTemplateInstantiation()),
              hasLoopInit(
                  anyOf(declStmt(declCountIs(2),
                                 containsDeclaration(0, InitToZeroMatcher),

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp?rev=245942&r1=245941&r2=245942&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-extra.cpp Tue Aug 25 10:44:00 2015
@@ -626,3 +626,24 @@ void messing_with_macros() {
 }
 
 } // 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




More information about the cfe-commits mailing list