10#include "../utils/Matchers.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
25 anyOf(hasThreadStorageDuration(), hasStaticStorageDuration()),
26 unless(anyOf(isConstexpr(), hasType(cxxRecordDecl(isLambda())),
27 hasAncestor(functionDecl()))),
28 anyOf(hasDescendant(cxxConstructExpr(hasDeclaration(
29 cxxConstructorDecl(unless(isNoThrow())).bind(
"func")))),
30 hasDescendant(cxxNewExpr(hasDeclaration(
31 functionDecl(unless(isNoThrow())).bind(
"func")))),
32 hasDescendant(callExpr(hasDeclaration(
33 functionDecl(unless(isNoThrow())).bind(
"func"))))))
39 const auto *VD = Result.Nodes.getNodeAs<VarDecl>(
"var");
40 const auto *Func = Result.Nodes.getNodeAs<FunctionDecl>(
"func");
42 diag(VD->getLocation(),
43 "initialization of %0 with %select{static|thread_local}1 storage "
44 "duration may throw an exception that cannot be caught")
45 << VD << (VD->getStorageDuration() == SD_Static ? 0 : 1);
47 SourceLocation FuncLocation = Func->getLocation();
48 if (FuncLocation.isValid()) {
50 "possibly throwing %select{constructor|function}0 declared here",
52 << (isa<CXXConstructorDecl>(Func) ? 0 : 1);
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.