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.
28 class DynamicStaticInitializersCheck : public ClangTidyCheck {
29 public:
30   DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context);
isLanguageVersionSupported(const LangOptions & LangOpts)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
48