clang-tools  14.0.0git
DefinitionsInHeadersCheck.h
Go to the documentation of this file.
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
35 public:
36  DefinitionsInHeadersCheck(StringRef Name, ClangTidyContext *Context);
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
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
clang::tidy::misc::DefinitionsInHeadersCheck::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: DefinitionsInHeadersCheck.cpp:44
clang::tidy::misc::DefinitionsInHeadersCheck
Finds non-extern non-inline function and variable definitions in header files, which can lead to pote...
Definition: DefinitionsInHeadersCheck.h:34
clang::tidy::misc::DefinitionsInHeadersCheck::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: DefinitionsInHeadersCheck.h:37
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:54
clang::tidy::misc::DefinitionsInHeadersCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: DefinitionsInHeadersCheck.cpp:69
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:72
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::misc::DefinitionsInHeadersCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: DefinitionsInHeadersCheck.cpp:50
clang::tidy::misc::DefinitionsInHeadersCheck::DefinitionsInHeadersCheck
DefinitionsInHeadersCheck(StringRef Name, ClangTidyContext *Context)
Definition: DefinitionsInHeadersCheck.cpp:30
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::utils::FileExtensionsSet
llvm::SmallSet< llvm::StringRef, 5 > FileExtensionsSet
Definition: FileExtensionsUtils.h:22