hokein created this revision.
Herald added subscribers: xazax.hun, JDevlieghere.

https://reviews.llvm.org/D36822

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  test/clang-tidy/modernize-make-unique.cpp


Index: test/clang-tidy/modernize-make-unique.cpp
===================================================================
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -451,3 +451,17 @@
     // CHECK-FIXES: (*this) = std::make_unique<Foo>();
   }
 };
+
+// Ignore statements inside a template instantiation.
+template<typename T>
+void template_fun(T* t) {
+  std::unique_ptr<T> t2 = std::unique_ptr<T>(new T);
+  // CHECK-MESSAGE-NOT: warning:
+  t2.reset(new T);
+  // CHECK-MESSAGE-NOT: warning:
+}
+
+void invoke_template() {
+  Foo* foo;
+  template_fun(foo);
+}
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===================================================================
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -86,15 +86,17 @@
                           
cxxNewExpr(hasType(pointsTo(qualType(hasCanonicalType(
                                          equalsBoundNode(PointerType))))),
                                      CanCallCtor)
-                              .bind(NewExpression)))
+                              .bind(NewExpression)),
+              unless(isInTemplateInstantiation()))
               .bind(ConstructorCall)))),
       this);
 
   Finder->addMatcher(
       cxxMemberCallExpr(
           thisPointerType(getSmartPointerTypeMatcher()),
           callee(cxxMethodDecl(hasName("reset"))),
-          hasArgument(0, cxxNewExpr(CanCallCtor).bind(NewExpression)))
+          hasArgument(0, cxxNewExpr(CanCallCtor).bind(NewExpression)),
+          unless(isInTemplateInstantiation()))
           .bind(ResetCall),
       this);
 }


Index: test/clang-tidy/modernize-make-unique.cpp
===================================================================
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -451,3 +451,17 @@
     // CHECK-FIXES: (*this) = std::make_unique<Foo>();
   }
 };
+
+// Ignore statements inside a template instantiation.
+template<typename T>
+void template_fun(T* t) {
+  std::unique_ptr<T> t2 = std::unique_ptr<T>(new T);
+  // CHECK-MESSAGE-NOT: warning:
+  t2.reset(new T);
+  // CHECK-MESSAGE-NOT: warning:
+}
+
+void invoke_template() {
+  Foo* foo;
+  template_fun(foo);
+}
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===================================================================
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -86,15 +86,17 @@
                           cxxNewExpr(hasType(pointsTo(qualType(hasCanonicalType(
                                          equalsBoundNode(PointerType))))),
                                      CanCallCtor)
-                              .bind(NewExpression)))
+                              .bind(NewExpression)),
+              unless(isInTemplateInstantiation()))
               .bind(ConstructorCall)))),
       this);
 
   Finder->addMatcher(
       cxxMemberCallExpr(
           thisPointerType(getSmartPointerTypeMatcher()),
           callee(cxxMethodDecl(hasName("reset"))),
-          hasArgument(0, cxxNewExpr(CanCallCtor).bind(NewExpression)))
+          hasArgument(0, cxxNewExpr(CanCallCtor).bind(NewExpression)),
+          unless(isInTemplateInstantiation()))
           .bind(ResetCall),
       this);
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to