clang-tools 6.0.0

DefinitionsInHeadersCheck.h
Go to the documentation of this file.
1 //===--- DefinitionsInHeadersCheck.h - clang-tidy----------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONS_IN_HEADERS_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONS_IN_HEADERS_H
12
13 #include "../ClangTidy.h"
14 #include "../utils/HeaderFileExtensionsUtils.h"
15
16 namespace clang {
17 namespace tidy {
18 namespace misc {
19
20 /// Finds non-extern non-inline function and variable definitions in header
21 /// files, which can lead to potential ODR violations.
22 ///
23 /// The check supports these options:
24 /// - `UseHeaderFileExtension`: Whether to use file extension to distinguish
25 /// header files. True by default.
26 /// - `HeaderFileExtensions`: a comma-separated list of filename extensions of
27 /// header files (The filename extension should not contain "." prefix).
28 /// ",h,hh,hpp,hxx" by default.
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);
37 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
38 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
39 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
40
41 private:
42 const bool UseHeaderFileExtension;
43 const std::string RawStringHeaderFileExtensions;
44 utils::HeaderFileExtensionsSet HeaderFileExtensions;
45 };
46
47 } // namespace misc
48 } // namespace tidy
49 } // namespace clang
50
51 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_DEFINITIONS_IN_HEADERS_H
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:73
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
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:46
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::utils::HeaderFileExtensionsSet
llvm::SmallSet< llvm::StringRef, 5 > HeaderFileExtensionsSet
Definition: HeaderFileExtensionsUtils.h:22
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:99
clang::tidy::misc::DefinitionsInHeadersCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: DefinitionsInHeadersCheck.cpp:52
clang::tidy::misc::DefinitionsInHeadersCheck::DefinitionsInHeadersCheck
DefinitionsInHeadersCheck(StringRef Name, ClangTidyContext *Context)
Definition: DefinitionsInHeadersCheck.cpp:31
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
Definition: AndroidTidyModule.cpp:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:104