clang-tools 8.0.0

BugproneTidyModule.cpp
Go to the documentation of this file.
1 //===--- BugproneTidyModule.cpp - clang-tidy ------------------------------===//
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 #include "../ClangTidy.h"
11 #include "../ClangTidyModule.h"
12 #include "../ClangTidyModuleRegistry.h"
13 #include "../cppcoreguidelines/NarrowingConversionsCheck.h"
14 #include "ArgumentCommentCheck.h"
15 #include "AssertSideEffectCheck.h"
16 #include "BoolPointerImplicitConversionCheck.h"
17 #include "CopyConstructorInitCheck.h"
18 #include "DanglingHandleCheck.h"
19 #include "ExceptionEscapeCheck.h"
20 #include "FoldInitTypeCheck.h"
21 #include "ForwardDeclarationNamespaceCheck.h"
22 #include "ForwardingReferenceOverloadCheck.h"
23 #include "InaccurateEraseCheck.h"
24 #include "IncorrectRoundingsCheck.h"
25 #include "IntegerDivisionCheck.h"
26 #include "LambdaFunctionNameCheck.h"
27 #include "MacroParenthesesCheck.h"
28 #include "MacroRepeatedSideEffectsCheck.h"
29 #include "MisplacedOperatorInStrlenInAllocCheck.h"
30 #include "MisplacedWideningCastCheck.h"
31 #include "MoveForwardingReferenceCheck.h"
32 #include "MultipleStatementMacroCheck.h"
33 #include "ParentVirtualCallCheck.h"
34 #include "SizeofContainerCheck.h"
35 #include "SizeofExpressionCheck.h"
36 #include "StringConstructorCheck.h"
37 #include "StringIntegerAssignmentCheck.h"
38 #include "StringLiteralWithEmbeddedNulCheck.h"
39 #include "SuspiciousEnumUsageCheck.h"
40 #include "SuspiciousMemsetUsageCheck.h"
41 #include "SuspiciousMissingCommaCheck.h"
42 #include "SuspiciousSemicolonCheck.h"
43 #include "SuspiciousStringCompareCheck.h"
44 #include "SwappedArgumentsCheck.h"
45 #include "TerminatingContinueCheck.h"
46 #include "ThrowKeywordMissingCheck.h"
47 #include "TooSmallLoopVariableCheck.h"
48 #include "UndefinedMemoryManipulationCheck.h"
49 #include "UndelegatedConstructorCheck.h"
50 #include "UnusedRaiiCheck.h"
51 #include "UnusedReturnValueCheck.h"
52 #include "UseAfterMoveCheck.h"
53 #include "VirtualNearMissCheck.h"
54
55 namespace clang {
56 namespace tidy {
57 namespace bugprone {
58
59 class BugproneModule : public ClangTidyModule {
60 public:
61 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
62 CheckFactories.registerCheck<ArgumentCommentCheck>(
63 "bugprone-argument-comment");
64 CheckFactories.registerCheck<AssertSideEffectCheck>(
65 "bugprone-assert-side-effect");
66 CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
67 "bugprone-bool-pointer-implicit-conversion");
68 CheckFactories.registerCheck<CopyConstructorInitCheck>(
69 "bugprone-copy-constructor-init");
70 CheckFactories.registerCheck<DanglingHandleCheck>(
71 "bugprone-dangling-handle");
72 CheckFactories.registerCheck<ExceptionEscapeCheck>(
73 "bugprone-exception-escape");
74 CheckFactories.registerCheck<FoldInitTypeCheck>(
75 "bugprone-fold-init-type");
76 CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
77 "bugprone-forward-declaration-namespace");
78 CheckFactories.registerCheck<ForwardingReferenceOverloadCheck>(
79 "bugprone-forwarding-reference-overload");
80 CheckFactories.registerCheck<InaccurateEraseCheck>(
81 "bugprone-inaccurate-erase");
82 CheckFactories.registerCheck<IncorrectRoundingsCheck>(
83 "bugprone-incorrect-roundings");
84 CheckFactories.registerCheck<IntegerDivisionCheck>(
85 "bugprone-integer-division");
86 CheckFactories.registerCheck<LambdaFunctionNameCheck>(
87 "bugprone-lambda-function-name");
88 CheckFactories.registerCheck<MacroParenthesesCheck>(
89 "bugprone-macro-parentheses");
90 CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
91 "bugprone-macro-repeated-side-effects");
92 CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
93 "bugprone-misplaced-operator-in-strlen-in-alloc");
94 CheckFactories.registerCheck<MisplacedWideningCastCheck>(
95 "bugprone-misplaced-widening-cast");
96 CheckFactories.registerCheck<MoveForwardingReferenceCheck>(
97 "bugprone-move-forwarding-reference");
98 CheckFactories.registerCheck<MultipleStatementMacroCheck>(
99 "bugprone-multiple-statement-macro");
100 CheckFactories.registerCheck<TooSmallLoopVariableCheck>(
101 "bugprone-too-small-loop-variable");
102 CheckFactories.registerCheck<cppcoreguidelines::NarrowingConversionsCheck>(
103 "bugprone-narrowing-conversions");
104 CheckFactories.registerCheck<ParentVirtualCallCheck>(
105 "bugprone-parent-virtual-call");
106 CheckFactories.registerCheck<SizeofContainerCheck>(
107 "bugprone-sizeof-container");
108 CheckFactories.registerCheck<SizeofExpressionCheck>(
109 "bugprone-sizeof-expression");
110 CheckFactories.registerCheck<StringConstructorCheck>(
111 "bugprone-string-constructor");
112 CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
113 "bugprone-string-integer-assignment");
114 CheckFactories.registerCheck<StringLiteralWithEmbeddedNulCheck>(
115 "bugprone-string-literal-with-embedded-nul");
116 CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
117 "bugprone-suspicious-enum-usage");
118 CheckFactories.registerCheck<SuspiciousMemsetUsageCheck>(
119 "bugprone-suspicious-memset-usage");
120 CheckFactories.registerCheck<SuspiciousMissingCommaCheck>(
121 "bugprone-suspicious-missing-comma");
122 CheckFactories.registerCheck<SuspiciousSemicolonCheck>(
123 "bugprone-suspicious-semicolon");
124 CheckFactories.registerCheck<SuspiciousStringCompareCheck>(
125 "bugprone-suspicious-string-compare");
126 CheckFactories.registerCheck<SwappedArgumentsCheck>(
127 "bugprone-swapped-arguments");
128 CheckFactories.registerCheck<TerminatingContinueCheck>(
129 "bugprone-terminating-continue");
130 CheckFactories.registerCheck<ThrowKeywordMissingCheck>(
131 "bugprone-throw-keyword-missing");
132 CheckFactories.registerCheck<UndefinedMemoryManipulationCheck>(
133 "bugprone-undefined-memory-manipulation");
134 CheckFactories.registerCheck<UndelegatedConstructorCheck>(
135 "bugprone-undelegated-constructor");
136 CheckFactories.registerCheck<UnusedRaiiCheck>(
137 "bugprone-unused-raii");
138 CheckFactories.registerCheck<UnusedReturnValueCheck>(
139 "bugprone-unused-return-value");
140 CheckFactories.registerCheck<UseAfterMoveCheck>(
141 "bugprone-use-after-move");
142 CheckFactories.registerCheck<VirtualNearMissCheck>(
143 "bugprone-virtual-near-miss");
144 }
145 };
146
147 } // namespace bugprone
148
149 // Register the BugproneTidyModule using this statically initialized variable.
150 static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
151 X("bugprone-module", "Adds checks for bugprone code constructs.");
152
153 // This anchor is used to force the linker to link in the generated object file
154 // and thus register the BugproneModule.
155 volatile int BugproneModuleAnchorSource = 0;
156
157 } // namespace tidy
158 } // namespace clang
SuspiciousEnumUsageCheck.h
ArgumentCommentCheck.h
clang::tidy::bugprone::ForwardDeclarationNamespaceCheck
Checks if an unused forward declaration is in a wrong namespace.
Definition: ForwardDeclarationNamespaceCheck.h:41
clang::tidy::bugprone::SwappedArgumentsCheck
Finds potentially swapped arguments by looking at implicit conversions.
Definition: SwappedArgumentsCheck.h:20
clang::tidy::bugprone::AssertSideEffectCheck
Finds assert() with side effect.
Definition: AssertSideEffectCheck.h:35
clang::tidy::bugprone::SuspiciousMemsetUsageCheck
Finds memset calls with potential mistakes in their arguments.
Definition: SuspiciousMemsetUsageCheck.h:23
ForwardingReferenceOverloadCheck.h
clang::tidy::bugprone::CopyConstructorInitCheck
Finds copy constructors where the ctor don&#39;t call the copy constructor of the base class...
Definition: CopyConstructorInitCheck.h:24
clang::tidy::bugprone::LambdaFunctionNameCheck
Detect when func or FUNCTION is being used from within a lambda.
Definition: LambdaFunctionNameCheck.h:25
StringIntegerAssignmentCheck.h
clang::tidy::bugprone::StringIntegerAssignmentCheck
Finds instances where an integer is assigned to a string.
Definition: StringIntegerAssignmentCheck.h:23
MacroRepeatedSideEffectsCheck.h
SwappedArgumentsCheck.h
clang::tidy::bugprone::SuspiciousEnumUsageCheck
The checker detects various cases when an enum is probably misused (as a bitmask).
Definition: SuspiciousEnumUsageCheck.h:23
clang::tidy::bugprone::SuspiciousStringCompareCheck
Find suspicious calls to string compare functions.
Definition: SuspiciousStringCompareCheck.h:23
ThrowKeywordMissingCheck.h
UndelegatedConstructorCheck.h
InaccurateEraseCheck.h
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:59
clang::tidy::bugprone::BoolPointerImplicitConversionCheck
Checks for conditions based on implicit conversion from a bool pointer to bool.
Definition: BoolPointerImplicitConversionCheck.h:30
clang::tidy::bugprone::SizeofContainerCheck
Find usages of sizeof on expressions of STL container types.
Definition: SizeofContainerCheck.h:24
clang::tidy::bugprone::UseAfterMoveCheck
The check warns if an object is used after it has been moved, without an intervening reinitialization...
Definition: UseAfterMoveCheck.h:24
clang::tidy::bugprone::ArgumentCommentCheck
Definition: ArgumentCommentCheck.h:34
clang::tidy::bugprone::MisplacedOperatorInStrlenInAllocCheck
Finds cases where 1 is added to the string in the argument to a function in the strlen() family inste...
Definition: MisplacedOperatorInStrlenInAllocCheck.h:25
UnusedRaiiCheck.h
clang::tidy::bugprone::MacroRepeatedSideEffectsCheck
Checks for repeated argument with side effects in macros.
Definition: MacroRepeatedSideEffectsCheck.h:20
clang::tidy::bugprone::MultipleStatementMacroCheck
Detect multiple statement macros that are used in unbraced conditionals.
Definition: MultipleStatementMacroCheck.h:25
clang::tidy::bugprone::ForwardingReferenceOverloadCheck
The checker looks for constructors that can act as copy or move constructors through their forwarding...
Definition: ForwardingReferenceOverloadCheck.h:30
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:27
clang::tidy::bugprone::FoldInitTypeCheck
Find and flag invalid initializer values in folds, e.g.
Definition: FoldInitTypeCheck.h:28
clang::tidy::bugprone::MisplacedWideningCastCheck
Find casts of calculation results to bigger type.
Definition: MisplacedWideningCastCheck.h:31
TooSmallLoopVariableCheck.h
clang::tidy::bugprone::StringLiteralWithEmbeddedNulCheck
Find suspicious string literals with embedded NUL characters.
Definition: StringLiteralWithEmbeddedNulCheck.h:23
BoolPointerImplicitConversionCheck.h
SizeofExpressionCheck.h
clang::tidy::bugprone::VirtualNearMissCheck
Checks for near miss of virtual methods.
Definition: VirtualNearMissCheck.h:27
clang::tidy::bugprone::MoveForwardingReferenceCheck
The check warns if std::move is applied to a forwarding reference (i.e.
Definition: MoveForwardingReferenceCheck.h:37
MisplacedOperatorInStrlenInAllocCheck.h
SuspiciousStringCompareCheck.h
CopyConstructorInitCheck.h
MultipleStatementMacroCheck.h
MacroParenthesesCheck.h
clang::tidy::bugprone::BugproneModule
Definition: BugproneTidyModule.cpp:59
UndefinedMemoryManipulationCheck.h
clang::tidy::bugprone::DanglingHandleCheck
Detect dangling references in value handlers like std::experimental::string_view. ...
Definition: DanglingHandleCheck.h:24
SizeofContainerCheck.h
VirtualNearMissCheck.h
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:84
IncorrectRoundingsCheck.h
clang::tidy::bugprone::IntegerDivisionCheck
Finds cases where integer division in a floating point context is likely to cause unintended loss of ...
Definition: IntegerDivisionCheck.h:24
StringConstructorCheck.h
clang::tidy::bugprone::StringConstructorCheck
Finds suspicious string constructor and check their parameters.
Definition: StringConstructorCheck.h:23
clang::tidy::bugprone::IncorrectRoundingsCheck
Checks the usage of patterns known to produce incorrect rounding.
Definition: IncorrectRoundingsCheck.h:27
MisplacedWideningCastCheck.h
LambdaFunctionNameCheck.h
ExceptionEscapeCheck.h
clang::tidy::bugprone::SizeofExpressionCheck
Find suspicious usages of sizeof expression.
Definition: SizeofExpressionCheck.h:23
clang::tidy::bugprone::ParentVirtualCallCheck
Finds calls to grand..-parent virtual methods instead of parent&#39;s.
Definition: ParentVirtualCallCheck.h:23
clang::tidy::X
static ClangTidyModuleRegistry::Add< bugprone::BugproneModule > X("bugprone-module", "Adds checks for bugprone code constructs.")
clang::tidy::bugprone::MacroParenthesesCheck
Finds macros that can have unexpected behaviour due to missing parentheses.
Definition: MacroParenthesesCheck.h:32
DanglingHandleCheck.h
AssertSideEffectCheck.h
clang::tidy::bugprone::UndelegatedConstructorCheck
Finds creation of temporary objects in constructors that look like a function call to another constru...
Definition: UndelegatedConstructorCheck.h:24
clang::tidy::bugprone::TooSmallLoopVariableCheck
This check gives a warning if a loop variable has a too small type which might not be able to represe...
Definition: TooSmallLoopVariableCheck.h:31
clang::tidy::bugprone::InaccurateEraseCheck
Checks for inaccurate use of the erase() method.
Definition: InaccurateEraseCheck.h:26
clang::tidy::bugprone::BugproneModule::addCheckFactories
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module...
Definition: BugproneTidyModule.cpp:61
clang::tidy::BugproneModuleAnchorSource
volatile int BugproneModuleAnchorSource
Definition: BugproneTidyModule.cpp:155
ParentVirtualCallCheck.h
clang::tidy::bugprone::ExceptionEscapeCheck
Finds functions which should not throw exceptions: Destructors, move constructors, move assignment operators, the main() function, swap() functions, functions marked with throw() or noexcept and functions given as option to the checker.
Definition: ExceptionEscapeCheck.h:28
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
SuspiciousSemicolonCheck.h
IntegerDivisionCheck.h
clang::tidy::cppcoreguidelines::NarrowingConversionsCheck
Checks for narrowing conversions, e.g: int i = 0; i += 0.1;.
Definition: NarrowingConversionsCheck.h:25
clang::tidy::bugprone::ThrowKeywordMissingCheck
Emits a warning about temporary objects whose type is (or is derived from) a class that has &#39;EXCEPTIO...
Definition: ThrowKeywordMissingCheck.h:24
clang::tidy::bugprone::TerminatingContinueCheck
Checks if a &#39;continue&#39; statement terminates the loop (i.e.
Definition: TerminatingContinueCheck.h:24
clang::tidy::bugprone::SuspiciousSemicolonCheck
This check finds semicolon that modifies the meaning of the program unintendedly. ...
Definition: SuspiciousSemicolonCheck.h:24
clang::tidy::bugprone::SuspiciousMissingCommaCheck
This check finds string literals which are probably concatenated accidentally.
Definition: SuspiciousMissingCommaCheck.h:24
UseAfterMoveCheck.h
clang::tidy::bugprone::UnusedRaiiCheck
Finds temporaries that look like RAII objects.
Definition: UnusedRaiiCheck.h:23
clang::tidy::bugprone::UnusedReturnValueCheck
Detects function calls where the return value is unused.
Definition: UnusedReturnValueCheck.h:24
ForwardDeclarationNamespaceCheck.h
SuspiciousMemsetUsageCheck.h
UnusedReturnValueCheck.h
SuspiciousMissingCommaCheck.h
StringLiteralWithEmbeddedNulCheck.h
FoldInitTypeCheck.h
TerminatingContinueCheck.h
clang::tidy::bugprone::UndefinedMemoryManipulationCheck
Finds calls of memory manipulation functions memset(), memcpy() and memmove() on not TriviallyCopyabl...
Definition: UndefinedMemoryManipulationCheck.h:25
MoveForwardingReferenceCheck.h