[clang-tidy] Fix a false positive in the make_pair checker if an argument has a explicit template argument.
This required a rather ugly workaround for a problem in ASTMatchers where
callee() is only overloaded for Stmt and Decl but not for Expr.
llvm-svn: 213509
diff --git a/clang-tools-extra/clang-tidy/google/ExplicitMakePairCheck.cpp b/clang-tools-extra/clang-tidy/google/ExplicitMakePairCheck.cpp
index ae5fbd6..e29b1ad 100644
--- a/clang-tools-extra/clang-tidy/google/ExplicitMakePairCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/ExplicitMakePairCheck.cpp
@@ -20,6 +20,15 @@
AST_MATCHER(DeclRefExpr, hasExplicitTemplateArgs) {
return Node.hasExplicitTemplateArgs();
}
+
+// FIXME: This should just be callee(ignoringImpCasts()) but it's not overloaded
+// for Expr.
+AST_MATCHER_P(CallExpr, calleeIgnoringParenImpCasts, internal::Matcher<Stmt>,
+ InnerMatcher) {
+ const Expr *ExprNode = Node.getCallee();
+ return (ExprNode != nullptr &&
+ InnerMatcher.matches(*ExprNode->IgnoreParenImpCasts(), Finder, Builder));
+}
} // namespace ast_matchers
namespace tidy {
@@ -33,8 +42,10 @@
callExpr(unless(hasAncestor(decl(anyOf(
recordDecl(ast_matchers::isTemplateInstantiation()),
functionDecl(ast_matchers::isTemplateInstantiation()))))),
- has(declRefExpr(hasExplicitTemplateArgs()).bind("declref")),
- callee(functionDecl(hasName("::std::make_pair")))).bind("call"),
+ calleeIgnoringParenImpCasts(
+ declRefExpr(hasExplicitTemplateArgs(),
+ to(functionDecl(hasName("::std::make_pair"))))
+ .bind("declref"))).bind("call"),
this);
}