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();
28 void ExplicitMakePairCheck::registerMatchers(
29 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"))))
47 void ExplicitMakePairCheck::check(
const MatchFinder::MatchResult &Result) {
48 const auto *Call = Result.Nodes.getNodeAs<CallExpr>(
"call");
49 const auto *
DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>(
"declref");
52 if (Call->getNumArgs() != 2)
55 const Expr *Arg0 = Call->getArg(0)->IgnoreParenImpCasts();
56 const Expr *Arg1 = Call->getArg(1)->IgnoreParenImpCasts();
61 if (Arg0->getType() != Call->getArg(0)->getType() ||
62 Arg1->getType() != Call->getArg(1)->getType()) {
63 diag(Call->getLocStart(),
"for C++11-compatibility, use pair directly")
64 << FixItHint::CreateReplacement(
65 SourceRange(DeclRef->getLocStart(), DeclRef->getLAngleLoc()),
68 diag(Call->getLocStart(),
69 "for C++11-compatibility, omit template arguments from make_pair")
70 << FixItHint::CreateRemoval(
71 SourceRange(DeclRef->getLAngleLoc(), DeclRef->getRAngleLoc()));
std::unique_ptr< ast_matchers::MatchFinder > Finder
AST_MATCHER(VarDecl, isAsm)
const DeclRefExpr * DeclRef