10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
19 const Stmt *Body =
Node.getBody();
20 return Body !=
nullptr && CoroutineBodyStmt::classof(Body);
23AST_MATCHER(LambdaExpr, hasCaptures) {
return Node.capture_size() != 0U; }
27 MatchFinder *Finder) {
29 lambdaExpr(hasCaptures(), hasCoroutineBody()).bind(
"lambda"),
this);
33 const LangOptions &LangOpts)
const {
34 return LangOpts.CPlusPlus20;
38 const MatchFinder::MatchResult &Result) {
39 const auto *MatchedLambda = Result.Nodes.getNodeAs<LambdaExpr>(
"lambda");
40 diag(MatchedLambda->getExprLoc(),
41 "coroutine lambda may cause use-after-free, avoid captures or ensure "
42 "lambda closure object has guaranteed lifetime");
::clang::DynTypedNode Node
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
AST_MATCHER(CXXRecordDecl, hasPublicVirtualOrProtectedNonVirtualDestructor)