11 #include "../utils/Matchers.h"
12 #include "clang/AST/ASTContext.h"
13 #include "clang/ASTMatchers/ASTMatchFinder.h"
15 using namespace clang::ast_matchers;
21 void StaticObjectExceptionCheck::registerMatchers(MatchFinder *
Finder) {
22 if (!getLangOpts().CPlusPlus)
28 varDecl(anyOf(hasThreadStorageDuration(), hasStaticStorageDuration()),
29 hasInitializer(cxxConstructExpr(hasDeclaration(
30 cxxConstructorDecl(unless(isNoThrow()))
36 void StaticObjectExceptionCheck::check(
const MatchFinder::MatchResult &
Result) {
37 const auto *VD = Result.Nodes.getNodeAs<VarDecl>(
"var");
38 const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>(
"ctor");
40 diag(VD->getLocation(),
41 "construction of %0 with %select{static|thread_local}1 storage "
42 "duration may throw an exception that cannot be caught")
43 << VD << (VD->getStorageDuration() == SD_Static ? 0 : 1);
44 diag(Ctor->getLocation(),
"possibly throwing constructor declared here",
std::unique_ptr< ast_matchers::MatchFinder > Finder