24 anyOf(hasThreadStorageDuration(), hasStaticStorageDuration()),
25 unless(anyOf(isConstexpr(), hasType(cxxRecordDecl(isLambda())),
26 hasAncestor(functionDecl()))),
27 anyOf(hasDescendant(cxxConstructExpr(hasDeclaration(
28 cxxConstructorDecl(unless(isNoThrow())).bind(
"func")))),
29 hasDescendant(cxxNewExpr(hasDeclaration(
30 functionDecl(unless(isNoThrow())).bind(
"func")))),
31 hasDescendant(callExpr(hasDeclaration(
32 functionDecl(unless(isNoThrow())).bind(
"func"))))))
38 const MatchFinder::MatchResult &Result) {
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);