77// ===----------------------------------------------------------------------===//
88
99#include " ThrowingStaticInitializationCheck.h"
10+ #include " ../utils/Matchers.h"
11+ #include " ../utils/OptionsUtils.h"
1012#include " clang/AST/ASTContext.h"
1113#include " clang/ASTMatchers/ASTMatchFinder.h"
1214
1315using namespace clang ::ast_matchers;
1416
1517namespace clang ::tidy::bugprone {
1618
19+ ThrowingStaticInitializationCheck::ThrowingStaticInitializationCheck (
20+ StringRef Name, ClangTidyContext *Context)
21+ : ClangTidyCheck(Name, Context),
22+ AllowedTypes (
23+ utils::options::parseStringList (Options.get(" AllowedTypes" , " " ))) {}
24+
25+ void ThrowingStaticInitializationCheck::storeOptions (
26+ ClangTidyOptions::OptionMap &Opts) {
27+ Options.store (Opts, " AllowedTypes" ,
28+ utils::options::serializeStringList (AllowedTypes));
29+ }
30+
1731void ThrowingStaticInitializationCheck::registerMatchers (MatchFinder *Finder) {
1832 // Match any static or thread_local variable declaration that has an
1933 // initializer that can throw.
@@ -22,8 +36,10 @@ void ThrowingStaticInitializationCheck::registerMatchers(MatchFinder *Finder) {
2236 TK_AsIs,
2337 varDecl (
2438 anyOf (hasThreadStorageDuration (), hasStaticStorageDuration ()),
25- unless (anyOf (isConstexpr (), hasType (cxxRecordDecl (isLambda ())),
26- hasAncestor (functionDecl ()))),
39+ unless (anyOf (
40+ isConstexpr (), hasType (cxxRecordDecl (isLambda ())),
41+ hasAncestor (functionDecl ()),
42+ hasType (matchers::matchesAnyListedTypeName (AllowedTypes)))),
2743 anyOf (hasDescendant (cxxConstructExpr (hasDeclaration (
2844 cxxConstructorDecl (unless (isNoThrow ())).bind (" func" )))),
2945 hasDescendant (cxxNewExpr (hasDeclaration (
0 commit comments