10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
18 auto CtorInitializerList =
19 cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
23 hasType(cxxRecordDecl(
24 isSameOrDerivedFrom(matchesName(
"[Ee]xception|EXCEPTION")))),
27 stmt(anyOf(cxxThrowExpr(), callExpr(), returnStmt()))),
28 hasAncestor(decl(anyOf(varDecl(), fieldDecl()))),
29 hasAncestor(expr(cxxNewExpr(hasAnyPlacementArg(anything())))),
30 allOf(hasAncestor(CtorInitializerList),
31 unless(hasAncestor(cxxCatchStmt()))))))
32 .bind(
"temporary-exception-not-thrown"),
37 const auto *TemporaryExpr =
38 Result.Nodes.getNodeAs<Expr>(
"temporary-exception-not-thrown");
40 diag(TemporaryExpr->getBeginLoc(),
"suspicious exception object created but "
41 "not thrown; did you mean 'throw %0'?")
42 << TemporaryExpr->getType().getBaseTypeIdentifier()->getName();
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
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.