clang-tools  8.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
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
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
llvm::SmallSet< llvm::StringRef, 5 > HeaderFileExtensionsSet
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
DefinitionsInHeadersCheck(StringRef Name, ClangTidyContext *Context)
Finds non-extern non-inline function and variable definitions in header files, which can lead to pote...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.