11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 20 void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
21 if (!getLangOpts().CPlusPlus)
24 auto CtorInitializerList =
25 cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
28 expr(anyOf(cxxFunctionalCastExpr(), cxxBindTemporaryExpr(),
29 cxxTemporaryObjectExpr()),
30 hasType(cxxRecordDecl(
31 isSameOrDerivedFrom(matchesName(
"[Ee]xception|EXCEPTION")))),
32 unless(anyOf(hasAncestor(stmt(
33 anyOf(cxxThrowExpr(), callExpr(), returnStmt()))),
34 hasAncestor(varDecl()),
35 allOf(hasAncestor(CtorInitializerList),
36 unless(hasAncestor(cxxCatchStmt()))))))
37 .bind(
"temporary-exception-not-thrown"),
41 void ThrowKeywordMissingCheck::check(
const MatchFinder::MatchResult &Result) {
42 const auto *TemporaryExpr =
43 Result.Nodes.getNodeAs<Expr>(
"temporary-exception-not-thrown");
45 diag(TemporaryExpr->getLocStart(),
"suspicious exception object created but " 46 "not thrown; did you mean 'throw %0'?")
47 << TemporaryExpr->getType().getBaseTypeIdentifier()->getName();
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//