clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
clang::tidy::ClangTidyCheck Class Reference

Base class for all clang-tidy checks. More...

`#include <ClangTidy.h>`

Inherits MatchCallback.

Inherited by clang::tidy::AssertSideEffectCheck, clang::tidy::cert::SetLongJmpCheck, clang::tidy::cert::StaticObjectExceptionCheck, clang::tidy::cert::ThrownExceptionTypeCheck, clang::tidy::cert::VariadicFunctionDefCheck, clang::tidy::google::build::ExplicitMakePairCheck, clang::tidy::google::build::UnnamedNamespaceInHeaderCheck, clang::tidy::google::build::UsingNamespaceDirectiveCheck, clang::tidy::google::ExplicitConstructorCheck, clang::tidy::google::readability::AvoidCStyleCastsCheck, clang::tidy::google::readability::GlobalNamesInHeadersCheck, clang::tidy::google::readability::TodoCommentCheck, clang::tidy::google::runtime::IntegerTypesCheck, clang::tidy::google::runtime::MemsetZeroLengthCheck, clang::tidy::google::runtime::OverloadedUnaryAndCheck, clang::tidy::google::runtime::StringReferenceMemberCheck, clang::tidy::HeaderGuardCheck, clang::tidy::ImplicitBoolCastCheck, clang::tidy::llvm::IncludeOrderCheck, clang::tidy::llvm::TwineLocalCheck, clang::tidy::MacroParenthesesCheck, clang::tidy::misc::ArgumentCommentCheck, clang::tidy::misc::AssignOperatorSignatureCheck, clang::tidy::misc::BoolPointerImplicitConversionCheck, clang::tidy::misc::DefinitionsInHeadersCheck, clang::tidy::misc::InaccurateEraseCheck, clang::tidy::misc::InefficientAlgorithmCheck, clang::tidy::misc::MacroRepeatedSideEffectsCheck, clang::tidy::misc::MoveConstantArgumentCheck, clang::tidy::misc::NewDeleteOverloadsCheck, clang::tidy::misc::SwappedArgumentsCheck, clang::tidy::misc::UndelegatedConstructorCheck, clang::tidy::misc::UniqueptrResetReleaseCheck, clang::tidy::misc::UnusedRAIICheck, clang::tidy::misc::VirtualNearMissCheck, clang::tidy::modernize::LoopConvertCheck, clang::tidy::modernize::MakeUniqueCheck, clang::tidy::modernize::PassByValueCheck, clang::tidy::modernize::RedundantVoidArgCheck, clang::tidy::modernize::ReplaceAutoPtrCheck, clang::tidy::modernize::ShrinkToFitCheck, clang::tidy::modernize::UseAutoCheck, clang::tidy::modernize::UseDefaultCheck, clang::tidy::modernize::UseNullptrCheck, clang::tidy::modernize::UseOverrideCheck, clang::tidy::MoveConstructorInitCheck, clang::tidy::NoexceptMoveConstructorCheck, clang::tidy::NonCopyableObjectsCheck, clang::tidy::performance::UnnecessaryCopyInitialization, clang::tidy::ProBoundsArrayToPointerDecayCheck, clang::tidy::ProBoundsConstantArrayIndexCheck, clang::tidy::ProBoundsPointerArithmeticCheck, clang::tidy::ProTypeConstCastCheck, clang::tidy::ProTypeCstyleCastCheck, clang::tidy::ProTypeReinterpretCastCheck, clang::tidy::ProTypeStaticCastDowncastCheck, clang::tidy::ProTypeUnionAccessCheck, clang::tidy::ProTypeVarargCheck, clang::tidy::readability::BracesAroundStatementsCheck, clang::tidy::readability::ContainerSizeEmptyCheck, clang::tidy::readability::ElseAfterReturnCheck, clang::tidy::readability::FunctionSizeCheck, clang::tidy::readability::IdentifierNamingCheck, clang::tidy::readability::InconsistentDeclarationParameterNameCheck, clang::tidy::readability::NamedParameterCheck, clang::tidy::readability::NamespaceCommentCheck, clang::tidy::readability::RedundantSmartptrGetCheck, clang::tidy::readability::RedundantStringCStrCheck, clang::tidy::readability::SimplifyBooleanExprCheck, clang::tidy::SizeofContainerCheck, clang::tidy::StaticAssertCheck, clang::tidy::StringIntegerAssignmentCheck, clang::tidy::ThrowByValueCatchByReferenceCheck, clang::tidy::UniqueptrDeleteReleaseCheck, clang::tidy::UnusedAliasDeclsCheck, and clang::tidy::UnusedParametersCheck.

Collaboration diagram for clang::tidy::ClangTidyCheck:
[legend]

## Public Member Functions
| ClangTidyCheck (StringRef CheckName, ClangTidyContext *Context)
| Initializes the check with `CheckName` and `Context`. More...
virtual void | registerPPCallbacks (CompilerInstance &Compiler)
| Override this to register `PPCallbacks` with `Compiler`. More...
virtual void | registerMatchers (ast_matchers::MatchFinder *Finder)
| Override this to register ASTMatchers with `Finder`. More...
virtual void | check (const ast_matchers::MatchFinder::MatchResult &Result)
| `ClangTidyChecks` that register ASTMatchers should do the actual work in here. More...
DiagnosticBuilder | diag (SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
| Add a diagnostic with the check's name. More...
virtual void | storeOptions (ClangTidyOptions::OptionMap &Options)
| Should store all options supported by this check with their current values or default values for options that haven't been overridden. More...

## Protected Member Functions
StringRef | getCurrentMainFile () const
| Returns the main file name of the current translation unit. More...
LangOptions | getLangOpts () const
| Returns the language options from the context. More...

## Protected Attributes
OptionsView | Options

## Detailed Description

Base class for all clang-tidy checks.

To implement a `ClangTidyCheck`, write a subclass and override some of the base class's methods. E.g. to implement a check that validates namespace declarations, override `registerMatchers:`

registerMatchers(ast_matchers::MatchFinder *Finder) {
Finder->addMatcher(namespaceDecl().bind("namespace"), this);
}

and then override `check(const MatchResult &Result)` to do the actual check for each match.

A new `ClangTidyCheck` instance is created per translation unit.

FIXME: Figure out whether carrying information from one TU to another is useful/necessary.

Definition at line 102 of file ClangTidy.h.

## Constructor & Destructor Documentation

clang::tidy::ClangTidyCheck::ClangTidyCheck | ( | StringRef | CheckName,
|  | ClangTidyContext * | Context
| ) |  |
| inline

Initializes the check with `CheckName` and `Context`.

Derived classes must implement the constructor with this signature or delegate it. If a check needs to read options, it can do this in the constructor using the Options.get() methods below.

Definition at line 109 of file ClangTidy.h.

## Member Function Documentation

virtual void clang::tidy::ClangTidyCheck::check | ( | const ast_matchers::MatchFinder::MatchResult & | Result | ) |
| inline virtual

`ClangTidyChecks` that register ASTMatchers should do the actual work in here.

Reimplemented in clang::tidy::readability::SimplifyBooleanExprCheck, clang::tidy::modernize::ReplaceAutoPtrCheck, clang::tidy::readability::BracesAroundStatementsCheck, clang::tidy::google::runtime::StringReferenceMemberCheck, clang::tidy::modernize::UseDefaultCheck, clang::tidy::google::build::UsingNamespaceDirectiveCheck, clang::tidy::misc::ArgumentCommentCheck, clang::tidy::AssertSideEffectCheck, clang::tidy::modernize::RedundantVoidArgCheck, clang::tidy::readability::IdentifierNamingCheck, clang::tidy::misc::UniqueptrResetReleaseCheck, clang::tidy::readability::FunctionSizeCheck, clang::tidy::misc::BoolPointerImplicitConversionCheck, clang::tidy::readability::NamedParameterCheck, clang::tidy::ProBoundsConstantArrayIndexCheck, clang::tidy::google::readability::AvoidCStyleCastsCheck, clang::tidy::ThrowByValueCatchByReferenceCheck, clang::tidy::misc::DefinitionsInHeadersCheck, clang::tidy::misc::VirtualNearMissCheck, clang::tidy::modernize::MakeUniqueCheck, clang::tidy::readability::ContainerSizeEmptyCheck, clang::tidy::readability::InconsistentDeclarationParameterNameCheck, clang::tidy::readability::RedundantSmartptrGetCheck, clang::tidy::performance::UnnecessaryCopyInitialization, clang::tidy::google::build::ExplicitMakePairCheck, clang::tidy::google::runtime::MemsetZeroLengthCheck, clang::tidy::misc::InaccurateEraseCheck, clang::tidy::ImplicitBoolCastCheck, clang::tidy::google::runtime::OverloadedUnaryAndCheck, clang::tidy::google::build::UnnamedNamespaceInHeaderCheck, clang::tidy::misc::AssignOperatorSignatureCheck, clang::tidy::MoveConstructorInitCheck, clang::tidy::NoexceptMoveConstructorCheck, clang::tidy::modernize::ShrinkToFitCheck, clang::tidy::cert::StaticObjectExceptionCheck, clang::tidy::misc::InefficientAlgorithmCheck, clang::tidy::misc::NewDeleteOverloadsCheck, clang::tidy::StaticAssertCheck, clang::tidy::misc::UndelegatedConstructorCheck, clang::tidy::readability::NamespaceCommentCheck, clang::tidy::cert::SetLongJmpCheck, clang::tidy::cert::ThrownExceptionTypeCheck, clang::tidy::cert::VariadicFunctionDefCheck, clang::tidy::ProBoundsPointerArithmeticCheck, clang::tidy::ProTypeCstyleCastCheck, clang::tidy::ProTypeUnionAccessCheck, clang::tidy::ProTypeVarargCheck, clang::tidy::google::runtime::IntegerTypesCheck, clang::tidy::SizeofContainerCheck, clang::tidy::misc::UnusedRAIICheck, clang::tidy::modernize::PassByValueCheck, clang::tidy::UniqueptrDeleteReleaseCheck, clang::tidy::ProBoundsArrayToPointerDecayCheck, clang::tidy::ProTypeConstCastCheck, clang::tidy::ProTypeReinterpretCastCheck, clang::tidy::ProTypeStaticCastDowncastCheck, clang::tidy::google::ExplicitConstructorCheck, clang::tidy::google::readability::GlobalNamesInHeadersCheck, clang::tidy::StringIntegerAssignmentCheck, clang::tidy::readability::ElseAfterReturnCheck, clang::tidy::llvm::TwineLocalCheck, clang::tidy::NonCopyableObjectsCheck, clang::tidy::misc::SwappedArgumentsCheck, clang::tidy::UnusedParametersCheck, clang::tidy::modernize::LoopConvertCheck, clang::tidy::modernize::UseAutoCheck, clang::tidy::modernize::UseOverrideCheck, clang::tidy::readability::RedundantStringCStrCheck, clang::tidy::misc::MoveConstantArgumentCheck, clang::tidy::UnusedAliasDeclsCheck, and clang::tidy::modernize::UseNullptrCheck.

Definition at line 138 of file ClangTidy.h.

DiagnosticBuilder clang::tidy::ClangTidyCheck::diag | ( | SourceLocation | Loc,
|  | StringRef | Description,
|  | DiagnosticIDs::Level | Level = `DiagnosticIDs::Warning`
| ) |  |

Add a diagnostic with the check's name.

Definition at line 323 of file ClangTidy.cpp.

References clang::tidy::ClangTidyContext::diag().

Referenced by clang::tidy::google::runtime::IntegerTypesCheck::check(), clang::tidy::modernize::PassByValueCheck::check(), clang::tidy::StaticAssertCheck::check(), clang::tidy::readability::NamespaceCommentCheck::check(), clang::tidy::performance::UnnecessaryCopyInitialization::check(), clang::tidy::misc::DefinitionsInHeadersCheck::check(), clang::tidy::readability::ContainerSizeEmptyCheck::check(), clang::tidy::ProBoundsConstantArrayIndexCheck::check(), clang::tidy::AssertSideEffectCheck::check(), clang::tidy::modernize::ReplaceAutoPtrCheck::check(), clang::tidy::google::readability::TodoCommentCheck::TodoCommentHandler::HandleComment(), clang::tidy::readability::FunctionSizeCheck::onEndOfTranslationUnit(), and clang::tidy::readability::IdentifierNamingCheck::onEndOfTranslationUnit().

StringRef clang::tidy::ClangTidyCheck::getCurrentMainFile | ( |  | ) | const
| inline protected

Returns the main file name of the current translation unit.

Definition at line 160 of file ClangTidy.h.

References clang::tidy::ClangTidyContext::getCurrentFile().

LangOptions clang::tidy::ClangTidyCheck::getLangOpts | ( |  | ) | const
| inline protected

Returns the language options from the context.

Definition at line 162 of file ClangTidy.h.

References clang::tidy::ClangTidyContext::getLangOpts().

Referenced by clang::tidy::modernize::UseNullptrCheck::registerMatchers(), clang::tidy::modernize::LoopConvertCheck::registerMatchers(), clang::tidy::modernize::PassByValueCheck::registerMatchers(), clang::tidy::google::runtime::IntegerTypesCheck::registerMatchers(), clang::tidy::readability::NamespaceCommentCheck::registerMatchers(), clang::tidy::StaticAssertCheck::registerMatchers(), clang::tidy::MoveConstructorInitCheck::registerMatchers(), clang::tidy::ProBoundsConstantArrayIndexCheck::registerMatchers(), clang::tidy::readability::ContainerSizeEmptyCheck::registerMatchers(), clang::tidy::ThrowByValueCatchByReferenceCheck::registerMatchers(), clang::tidy::modernize::ReplaceAutoPtrCheck::registerMatchers(), clang::tidy::modernize::PassByValueCheck::registerPPCallbacks(), clang::tidy::ProBoundsConstantArrayIndexCheck::registerPPCallbacks(), and clang::tidy::modernize::ReplaceAutoPtrCheck::registerPPCallbacks().

virtual void clang::tidy::ClangTidyCheck::registerMatchers | ( | ast_matchers::MatchFinder * | Finder | ) |
| inline virtual

Override this to register ASTMatchers with `Finder`.

This should be used by clang-tidy checks that analyze code properties that dependent on AST knowledge.

You can register as many matchers as necessary with `Finder`. Usually, "this" will be used as callback, but you can also specify other callback classes. Thereby, different matchers can trigger different callbacks.

If you need to merge information between the different matchers, you can store these as members of the derived class. However, note that all matches occur in the order of the AST traversal.

Reimplemented in clang::tidy::readability::SimplifyBooleanExprCheck, clang::tidy::modernize::ReplaceAutoPtrCheck, clang::tidy::readability::BracesAroundStatementsCheck, clang::tidy::google::runtime::StringReferenceMemberCheck, clang::tidy::modernize::UseDefaultCheck, clang::tidy::google::build::UsingNamespaceDirectiveCheck, clang::tidy::misc::ArgumentCommentCheck, clang::tidy::AssertSideEffectCheck, clang::tidy::modernize::RedundantVoidArgCheck, clang::tidy::readability::IdentifierNamingCheck, clang::tidy::misc::UniqueptrResetReleaseCheck, clang::tidy::readability::FunctionSizeCheck, clang::tidy::misc::BoolPointerImplicitConversionCheck, clang::tidy::readability::NamedParameterCheck, clang::tidy::google::readability::AvoidCStyleCastsCheck, clang::tidy::ThrowByValueCatchByReferenceCheck, clang::tidy::ProBoundsConstantArrayIndexCheck, clang::tidy::misc::DefinitionsInHeadersCheck, clang::tidy::misc::VirtualNearMissCheck, clang::tidy::modernize::MakeUniqueCheck, clang::tidy::readability::ContainerSizeEmptyCheck, clang::tidy::readability::InconsistentDeclarationParameterNameCheck, clang::tidy::readability::RedundantSmartptrGetCheck, clang::tidy::performance::UnnecessaryCopyInitialization, clang::tidy::google::build::ExplicitMakePairCheck, clang::tidy::google::runtime::MemsetZeroLengthCheck, clang::tidy::misc::InaccurateEraseCheck, clang::tidy::ImplicitBoolCastCheck, clang::tidy::google::runtime::OverloadedUnaryAndCheck, clang::tidy::google::build::UnnamedNamespaceInHeaderCheck, clang::tidy::misc::AssignOperatorSignatureCheck, clang::tidy::MoveConstructorInitCheck, clang::tidy::NoexceptMoveConstructorCheck, clang::tidy::modernize::ShrinkToFitCheck, clang::tidy::cert::StaticObjectExceptionCheck, clang::tidy::misc::InefficientAlgorithmCheck, clang::tidy::misc::NewDeleteOverloadsCheck, clang::tidy::StaticAssertCheck, clang::tidy::misc::UndelegatedConstructorCheck, clang::tidy::readability::NamespaceCommentCheck, clang::tidy::cert::SetLongJmpCheck, clang::tidy::cert::ThrownExceptionTypeCheck, clang::tidy::cert::VariadicFunctionDefCheck, clang::tidy::ProBoundsPointerArithmeticCheck, clang::tidy::ProTypeCstyleCastCheck, clang::tidy::ProTypeUnionAccessCheck, clang::tidy::ProTypeVarargCheck, clang::tidy::google::runtime::IntegerTypesCheck, clang::tidy::SizeofContainerCheck, clang::tidy::misc::UnusedRAIICheck, clang::tidy::modernize::PassByValueCheck, clang::tidy::UniqueptrDeleteReleaseCheck, clang::tidy::ProBoundsArrayToPointerDecayCheck, clang::tidy::ProTypeConstCastCheck, clang::tidy::ProTypeReinterpretCastCheck, clang::tidy::ProTypeStaticCastDowncastCheck, clang::tidy::google::ExplicitConstructorCheck, clang::tidy::google::readability::GlobalNamesInHeadersCheck, clang::tidy::StringIntegerAssignmentCheck, clang::tidy::readability::ElseAfterReturnCheck, clang::tidy::llvm::TwineLocalCheck, clang::tidy::NonCopyableObjectsCheck, clang::tidy::misc::SwappedArgumentsCheck, clang::tidy::UnusedParametersCheck, clang::tidy::modernize::LoopConvertCheck, clang::tidy::modernize::UseAutoCheck, clang::tidy::modernize::UseOverrideCheck, clang::tidy::readability::RedundantStringCStrCheck, clang::tidy::misc::MoveConstantArgumentCheck, clang::tidy::UnusedAliasDeclsCheck, and clang::tidy::modernize::UseNullptrCheck.

Definition at line 134 of file ClangTidy.h.

virtual void clang::tidy::ClangTidyCheck::registerPPCallbacks | ( | CompilerInstance & | Compiler | ) |
| inline virtual

Override this to register `PPCallbacks` with `Compiler`.

This should be used for clang-tidy checks that analyze preprocessor- dependent properties, e.g. the order of include directives.

Reimplemented in clang::tidy::modernize::ReplaceAutoPtrCheck, clang::tidy::MacroParenthesesCheck, clang::tidy::ProBoundsConstantArrayIndexCheck, clang::tidy::cert::SetLongJmpCheck, clang::tidy::google::readability::TodoCommentCheck, clang::tidy::llvm::IncludeOrderCheck, clang::tidy::misc::MacroRepeatedSideEffectsCheck, and clang::tidy::HeaderGuardCheck.

Definition at line 120 of file ClangTidy.h.

virtual void clang::tidy::ClangTidyCheck::storeOptions | ( | ClangTidyOptions::OptionMap & | Options | ) |
| inline virtual

Should store all options supported by this check with their current values or default values for options that haven't been overridden.

The check should use `Options.store()` to store each option it supports whether it has the default value or it has been overridden.

Reimplemented in clang::tidy::readability::SimplifyBooleanExprCheck, clang::tidy::modernize::ReplaceAutoPtrCheck, clang::tidy::readability::BracesAroundStatementsCheck, clang::tidy::AssertSideEffectCheck, clang::tidy::readability::IdentifierNamingCheck, clang::tidy::readability::FunctionSizeCheck, clang::tidy::ProBoundsConstantArrayIndexCheck, clang::tidy::MoveConstructorInitCheck, clang::tidy::ThrowByValueCatchByReferenceCheck, clang::tidy::misc::DefinitionsInHeadersCheck, clang::tidy::google::runtime::IntegerTypesCheck, clang::tidy::modernize::PassByValueCheck, clang::tidy::modernize::LoopConvertCheck, and clang::tidy::modernize::UseNullptrCheck.

Definition at line 149 of file ClangTidy.h.

## Member Data Documentation

OptionsView clang::tidy::ClangTidyCheck::Options
| protected

Definition at line 158 of file ClangTidy.h.

Referenced by clang::tidy::readability::IdentifierNamingCheck::IdentifierNamingCheck(), clang::tidy::modernize::UseNullptrCheck::storeOptions(), clang::tidy::modernize::LoopConvertCheck::storeOptions(), clang::tidy::modernize::PassByValueCheck::storeOptions(), clang::tidy::google::runtime::IntegerTypesCheck::storeOptions(), clang::tidy::misc::DefinitionsInHeadersCheck::storeOptions(), clang::tidy::MoveConstructorInitCheck::storeOptions(), clang::tidy::ThrowByValueCatchByReferenceCheck::storeOptions(), clang::tidy::ProBoundsConstantArrayIndexCheck::storeOptions(), clang::tidy::readability::FunctionSizeCheck::storeOptions(), clang::tidy::readability::IdentifierNamingCheck::storeOptions(), clang::tidy::AssertSideEffectCheck::storeOptions(), clang::tidy::modernize::ReplaceAutoPtrCheck::storeOptions(), clang::tidy::readability::BracesAroundStatementsCheck::storeOptions(), and clang::tidy::readability::SimplifyBooleanExprCheck::storeOptions().

The documentation for this class was generated from the following files:

- ClangTidy.h
- ClangTidy.cpp