10#include "../utils/Matchers.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/AST/ExprConcepts.h"
13#include "clang/ASTMatchers/ASTMatchFinder.h"
21using matchers::hasUnevaluatedContext;
24 ast_matchers::internal::Matcher<QualType>, InnerMatcher) {
25 return InnerMatcher.matches(
Node.getNonPackExpansionType(), Finder,
Builder);
29 ast_matchers::internal::Matcher<QualType>
Inner = possiblyPackExpansionOf(
30 qualType(rValueReferenceType(),
31 references(templateTypeParmType(
32 hasDeclaration(templateTypeParmDecl()))),
33 unless(references(qualType(isConstQualified())))));
37 const auto *
Function = dyn_cast<FunctionDecl>(
Node.getDeclContext());
41 const FunctionTemplateDecl *FuncTemplate =
42 Function->getDescribedFunctionTemplate();
47 Node.getType().getNonPackExpansionType()->getPointeeType();
48 const auto *TemplateType = ParamType->getAs<TemplateTypeParmType>();
52 return TemplateType->getDepth() ==
53 FuncTemplate->getTemplateParameters()->getDepth();
59 auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode(
"param")));
61 auto ForwardCallMatcher = callExpr(
62 forCallable(equalsBoundNode(
"func")), argumentCountIs(1),
63 callee(unresolvedLookupExpr(hasAnyDeclaration(
64 namedDecl(hasUnderlyingDecl(hasName(
"::std::forward")))))),
65 hasArgument(0, declRefExpr(to(equalsBoundNode(
"param"))).bind(
"ref")),
66 unless(anyOf(hasAncestor(typeLoc()),
67 hasAncestor(expr(hasUnevaluatedContext())))));
70 parmVarDecl(parmVarDecl().bind(
"param"), isTemplateTypeParameter(),
71 hasAncestor(functionDecl().bind(
"func")),
72 hasAncestor(functionDecl(
73 isDefinition(), equalsBoundNode(
"func"), ToParam,
74 unless(hasDescendant(std::move(ForwardCallMatcher)))))),
79 const auto *Param = Result.Nodes.getNodeAs<ParmVarDecl>(
"param");
84 diag(Param->getLocation(),
85 "forwarding reference parameter %0 is never forwarded "
86 "inside the function body")
std::pair< Context, Canceler > Inner
CodeCompletionBuilder Builder
::clang::DynTypedNode Node
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
AST_MATCHER_P(UserDefinedLiteral, hasLiteral, clang::ast_matchers::internal::Matcher< Expr >, InnerMatcher)
AST_MATCHER(FieldDecl, hasIntBitwidth)