[PATCH] D36822: [clang-tidy] Ignore statements inside a template instantiation.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 17 03:35:49 PDT 2017
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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36822.111487.patch
Type: text/x-patch
Size: 1668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170817/d8796077/attachment-0001.bin>
More information about the cfe-commits
mailing list