10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
19 void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
20 auto CtorInitializerList =
21 cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
24 expr(anyOf(cxxFunctionalCastExpr(), cxxBindTemporaryExpr(),
25 cxxTemporaryObjectExpr()),
26 hasType(cxxRecordDecl(
27 isSameOrDerivedFrom(matchesName(
"[Ee]xception|EXCEPTION")))),
28 unless(anyOf(hasAncestor(stmt(
29 anyOf(cxxThrowExpr(), callExpr(), returnStmt()))),
30 hasAncestor(varDecl()),
31 allOf(hasAncestor(CtorInitializerList),
32 unless(hasAncestor(cxxCatchStmt()))))))
33 .bind(
"temporary-exception-not-thrown"),
37 void ThrowKeywordMissingCheck::check(
const MatchFinder::MatchResult &Result) {
38 const auto *TemporaryExpr =
39 Result.Nodes.getNodeAs<Expr>(
"temporary-exception-not-thrown");
41 diag(TemporaryExpr->getBeginLoc(),
"suspicious exception object created but "
42 "not thrown; did you mean 'throw %0'?")
43 << TemporaryExpr->getType().getBaseTypeIdentifier()->getName();