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 HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
35 varDecl(hasGlobalStorage(), unless(hasConstantDeclaration())).bind(
"var"),
40 const auto *Var = Result.Nodes.getNodeAs<VarDecl>(
"var");
41 SourceLocation
Loc = Var->getLocation();
43 HeaderFileExtensions))
47 diag(
Loc,
"static variable %0 may be dynamically initialized in this header file")
llvm::SmallString< 256U > Name
::clang::DynTypedNode Node
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.
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.
AST_MATCHER(clang::VarDecl, hasConstantDeclaration)
bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether presumed location of Loc is in header file.