30AST_MATCHER_P2(Stmt, argumentOf,
bool, AllowPartialMove, StatementMatcher,
33 return stmt(anyOf(Ref, hasDescendant(Ref))).matches(Node, Finder, Builder);
40 auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode(
"param")));
42 StatementMatcher MoveCallMatcher =
45 anyOf(callee(functionDecl(hasName(MoveFunction))),
46 callee(unresolvedLookupExpr(hasAnyDeclaration(
47 namedDecl(hasUnderlyingDecl(hasName(MoveFunction))))))),
51 declRefExpr(to(equalsBoundNode(
"param"))).bind(
"ref"))),
53 lambdaExpr(valueCapturesVar(equalsBoundNode(
"param"))))),
54 unless(anyOf(hasAncestor(typeLoc()),
55 hasAncestor(expr(hasUnevaluatedContext())))))
60 hasType(type(rValueReferenceType())), parmVarDecl().bind(
"param"),
61 unless(hasType(references(qualType(
62 anyOf(isConstQualified(), substTemplateTypeParmType()))))),
63 optionally(hasType(qualType(references(templateTypeParmType(
64 hasDeclaration(templateTypeParmDecl().bind(
"template-type"))))))),
67 isDefinition(), unless(isDeleted()), unless(isDefaulted()),
68 unless(cxxConstructorDecl(isMoveConstructor())),
69 unless(cxxMethodDecl(isMoveAssignmentOperator())), ToParam,
70 anyOf(cxxConstructorDecl(
71 optionally(hasDescendant(MoveCallMatcher))),
72 functionDecl(unless(cxxConstructorDecl()),
74 hasDescendant(MoveCallMatcher))))))
80 const MatchFinder::MatchResult &Result) {
81 const auto *Param = Result.Nodes.getNodeAs<ParmVarDecl>(
"param");
82 const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>(
"func");
83 const auto *TemplateType =
84 Result.Nodes.getNodeAs<TemplateTypeParmDecl>(
"template-type");
86 if (!Param || !Function)
89 if (IgnoreUnnamedParams && Param->getName().empty())
92 if (!Param->isUsed() && Param->hasAttr<UnusedAttr>())
95 if (IgnoreNonDeducedTemplateTypes && TemplateType)
99 if (
const FunctionTemplateDecl *FuncTemplate =
100 Function->getDescribedFunctionTemplate()) {
101 const TemplateParameterList *Params =
102 FuncTemplate->getTemplateParameters();
103 if (llvm::is_contained(*Params, TemplateType)) {
110 const auto *MoveCall = Result.Nodes.getNodeAs<CallExpr>(
"move-call");
112 diag(Param->getLocation(),
113 "rvalue reference parameter %0 is never moved from "
114 "inside the function body")
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.