1 //===--- DefinitionsInHeadersCheck.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_MISC_DEFINITIONS_IN_HEADERS_H 10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONS_IN_HEADERS_H 11 12 #include "../ClangTidyCheck.h" 13 #include "../utils/FileExtensionsUtils.h" 14 15 namespace clang { 16 namespace tidy { 17 namespace misc { 18 19 /// Finds non-extern non-inline function and variable definitions in header 20 /// files, which can lead to potential ODR violations. 21 /// 22 /// The check supports these options: 23 /// - `UseHeaderFileExtension`: Whether to use file extension to distinguish 24 /// header files. True by default. 25 /// - `HeaderFileExtensions`: a semicolon-separated list of filename 26 /// extensions of header files (The filename extension should not contain 27 /// "." prefix). ";h;hh;hpp;hxx" by default. 28 /// 29 /// For extension-less header files, using an empty string or leaving an 30 /// empty string between ";" if there are other filename extensions. 31 /// 32 /// For the user-facing documentation see: 33 /// http://clang.llvm.org/extra/clang-tidy/checks/misc-definitions-in-headers.html 34 class DefinitionsInHeadersCheck : public ClangTidyCheck { 35 public: 36 DefinitionsInHeadersCheck(StringRef Name, ClangTidyContext *Context); isLanguageVersionSupported(const LangOptions & LangOpts)37 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { 38 return LangOpts.CPlusPlus11; 39 } 40 void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 41 void registerMatchers(ast_matchers::MatchFinder *Finder) override; 42 void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 43 44 private: 45 const bool UseHeaderFileExtension; 46 const std::string RawStringHeaderFileExtensions; 47 utils::FileExtensionsSet HeaderFileExtensions; 48 }; 49 50 } // namespace misc 51 } // namespace tidy 52 } // namespace clang 53 54 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONS_IN_HEADERS_H 55