38 anyOf(hasThreadStorageDuration(), hasStaticStorageDuration()),
40 isConstexpr(), hasType(cxxRecordDecl(isLambda())),
41 hasAncestor(functionDecl()),
43 anyOf(hasDescendant(cxxConstructExpr(hasDeclaration(
44 cxxConstructorDecl(unless(isNoThrow())).bind(
"func")))),
45 hasDescendant(cxxNewExpr(hasDeclaration(
46 functionDecl(unless(isNoThrow())).bind(
"func")))),
47 hasDescendant(callExpr(hasDeclaration(
48 functionDecl(unless(isNoThrow())).bind(
"func"))))))
54 const MatchFinder::MatchResult &Result) {
55 const auto *VD = Result.Nodes.getNodeAs<VarDecl>(
"var");
56 const auto *Func = Result.Nodes.getNodeAs<FunctionDecl>(
"func");
58 diag(VD->getLocation(),
59 "initialization of %0 with %select{static|thread_local}1 storage "
60 "duration may throw an exception that cannot be caught")
61 << VD << (VD->getStorageDuration() == SD_Static ? 0 : 1);
63 const SourceLocation FuncLocation = Func->getLocation();
64 if (FuncLocation.isValid()) {
66 "possibly throwing %select{constructor|function}0 declared here",
68 << (isa<CXXConstructorDecl>(Func) ? 0 : 1);
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.