DefinitionsInHeadersCheck.h 2.1 KB

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