10#include "../utils/FileExtensionsUtils.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
19 const Expr *Init = Node.getInit();
20 if (Init && !Init->isValueDependent()) {
21 if (Node.isConstexpr())
23 return Node.evaluateValue();
31 std::optional<StringRef> HeaderFileExtensionsOption =
33 RawStringHeaderFileExtensions =
35 if (HeaderFileExtensionsOption) {
40 << RawStringHeaderFileExtensions;
43 HeaderFileExtensions = Context->getHeaderFileExtensions();
48 Options.
store(Opts,
"HeaderFileExtensions", RawStringHeaderFileExtensions);
53 varDecl(hasGlobalStorage(), unless(hasConstantDeclaration())).bind(
"var"),
58 const auto *Var = Result.Nodes.getNodeAs<VarDecl>(
"var");
59 SourceLocation
Loc = Var->getLocation();
61 HeaderFileExtensions))
65 diag(
Loc,
"static variable %0 may be dynamically initialized in this header file")
std::optional< StringRef > get(StringRef LocalName) const
Read a named option from the Context.
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
Base class for all clang-tidy checks.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
DiagnosticBuilder configurationDiag(StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) const
Adds a diagnostic to report errors in the check's configuration.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context)
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.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
AST_MATCHER(clang::VarDecl, hasConstantDeclaration)
bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether presumed location of Loc is in header file.
StringRef defaultHeaderFileExtensions()
Returns recommended default value for the list of header file extensions.
StringRef defaultFileExtensionDelimiters()
Returns recommended default value for the list of file extension delimiters.
bool parseFileExtensions(StringRef AllFileExtensions, FileExtensionsSet &FileExtensions, StringRef Delimiters)
Parses header file extensions from a semicolon-separated list.
llvm::StringMap< ClangTidyValue > OptionMap