11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 #include "clang/ASTMatchers/ASTMatchers.h"
15 using namespace clang::ast_matchers;
20 return Node.hasExplicitTemplateArgs();
29 ExplicitMakePairCheck::registerMatchers(ast_matchers::MatchFinder *
Finder) {
32 if (!getLangOpts().CPlusPlus)
38 callExpr(unless(isInTemplateInstantiation()),
39 callee(expr(ignoringParenImpCasts(
40 declRefExpr(hasExplicitTemplateArgs(),
41 to(functionDecl(hasName(
"::std::make_pair"))))
42 .bind(
"declref"))))).bind(
"call"),
46 void ExplicitMakePairCheck::check(
const MatchFinder::MatchResult &
Result) {
47 const auto *Call = Result.Nodes.getNodeAs<CallExpr>(
"call");
48 const auto *DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>(
"declref");
51 if (Call->getNumArgs() != 2)
54 const Expr *Arg0 = Call->getArg(0)->IgnoreParenImpCasts();
55 const Expr *Arg1 = Call->getArg(1)->IgnoreParenImpCasts();
60 if (Arg0->getType() != Call->getArg(0)->getType() ||
61 Arg1->getType() != Call->getArg(1)->getType()) {
62 diag(Call->getLocStart(),
"for C++11-compatibility, use pair directly")
63 << FixItHint::CreateReplacement(
64 SourceRange(DeclRef->getLocStart(), DeclRef->getLAngleLoc()),
67 diag(Call->getLocStart(),
68 "for C++11-compatibility, omit template arguments from make_pair")
69 << FixItHint::CreateRemoval(
70 SourceRange(DeclRef->getLAngleLoc(), DeclRef->getRAngleLoc()));
std::unique_ptr< ast_matchers::MatchFinder > Finder
AST_MATCHER(Stmt, isInsideOfRangeBeginEndStmt)