clang-tools  14.0.0git
DynamicStaticInitializersCheck.h
Go to the documentation of this file.
1 //===--- DynamicStaticInitializersCheck.h - clang-tidy ----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMIC_STATIC_INITIALIZERS_CHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMIC_STATIC_INITIALIZERS_CHECK_H
11 
12 #include "../ClangTidyCheck.h"
13 #include "../utils/FileExtensionsUtils.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace bugprone {
18 
19 /// Finds dynamically initialized static variables in header files.
20 ///
21 /// The check supports these options:
22 /// - `HeaderFileExtensions`: a semicolon-separated list of filename
23 /// extensions of header files (The filename extensions should not contain
24 /// "." prefix). ";h;hh;hpp;hxx" by default.
25 //
26 /// For extension-less header files, using an empty string or leaving an
27 /// empty string between ";" if there are other filename extensions.
29 public:
31  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
32  return LangOpts.CPlusPlus && !LangOpts.ThreadsafeStatics;
33  }
34  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
35  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
36  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
37 
38 private:
39  const std::string RawStringHeaderFileExtensions;
40  utils::FileExtensionsSet HeaderFileExtensions;
41 };
42 
43 } // namespace bugprone
44 } // namespace tidy
45 } // namespace clang
46 
47 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMIC_STATIC_INITIALIZERS_CHECK_H
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
clang::tidy::bugprone::DynamicStaticInitializersCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: DynamicStaticInitializersCheck.cpp:47
clang::tidy::bugprone::DynamicStaticInitializersCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: DynamicStaticInitializersCheck.cpp:53
clang::tidy::bugprone::DynamicStaticInitializersCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: DynamicStaticInitializersCheck.cpp:42
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:54
clang::tidy::bugprone::DynamicStaticInitializersCheck::DynamicStaticInitializersCheck
DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context)
Definition: DynamicStaticInitializersCheck.cpp:29
clang::tidy::bugprone::DynamicStaticInitializersCheck
Finds dynamically initialized static variables in header files.
Definition: DynamicStaticInitializersCheck.h:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:71
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::bugprone::DynamicStaticInitializersCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
Definition: DynamicStaticInitializersCheck.h:31
clang::tidy::utils::FileExtensionsSet
llvm::SmallSet< llvm::StringRef, 5 > FileExtensionsSet
Definition: FileExtensionsUtils.h:22