[clang-tidy] Ignore substituted template types in modernize-use-nullptr check.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: xazax.hun, malcolm.parsons, JDevlieghere, cfe-commits

Differential Revision: https://reviews.llvm.org/D30639

llvm-svn: 297009
This commit is contained in:
Haojian Wu
2017-03-06 14:46:44 +00:00
parent c215a2ac40
commit 1aa5885f00
2 changed files with 18 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ AST_MATCHER(Type, sugaredNullptrType) {
StatementMatcher makeCastSequenceMatcher() {
StatementMatcher ImplicitCastToNull = implicitCastExpr(
anyOf(hasCastKind(CK_NullToPointer), hasCastKind(CK_NullToMemberPointer)),
unless(hasImplicitDestinationType(qualType(substTemplateTypeParmType()))),
unless(hasSourceExpression(hasType(sugaredNullptrType()))));
return castExpr(anyOf(ImplicitCastToNull,

View File

@@ -244,3 +244,20 @@ void f() {
bool a;
a = ZZ(Hash());
}
// Test on ignoring substituted template types.
template<typename T>
class TemplateClass {
public:
explicit TemplateClass(int a, T default_value = 0) {}
void h(T *default_value = 0) {}
void f(int* p = 0) {}
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use nullptr
// CHECK-FIXES: void f(int* p = nullptr) {}
};
void IgnoreSubstTemplateType() {
TemplateClass<int*> a(1);
}