clang-tools 10.0.0

BugproneTidyModule.cpp
Go to the documentation of this file.
1 //===--- BugproneTidyModule.cpp - clang-tidy ------------------------------===//
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 #include "../ClangTidy.h"
10 #include "../ClangTidyModule.h"
11 #include "../ClangTidyModuleRegistry.h"
12 #include "../cppcoreguidelines/NarrowingConversionsCheck.h"
13 #include "ArgumentCommentCheck.h"
14 #include "AssertSideEffectCheck.h"
15 #include "BadSignalToKillThreadCheck.h"
16 #include "BoolPointerImplicitConversionCheck.h"
17 #include "BranchCloneCheck.h"
18 #include "CopyConstructorInitCheck.h"
19 #include "DanglingHandleCheck.h"
20 #include "DynamicStaticInitializersCheck.h"
21 #include "ExceptionEscapeCheck.h"
22 #include "FoldInitTypeCheck.h"
23 #include "ForwardDeclarationNamespaceCheck.h"
24 #include "ForwardingReferenceOverloadCheck.h"
25 #include "InaccurateEraseCheck.h"
26 #include "IncorrectRoundingsCheck.h"
27 #include "InfiniteLoopCheck.h"
28 #include "IntegerDivisionCheck.h"
29 #include "LambdaFunctionNameCheck.h"
30 #include "MacroParenthesesCheck.h"
31 #include "MacroRepeatedSideEffectsCheck.h"
32 #include "MisplacedOperatorInStrlenInAllocCheck.h"
33 #include "MisplacedWideningCastCheck.h"
34 #include "MoveForwardingReferenceCheck.h"
35 #include "MultipleStatementMacroCheck.h"
36 #include "NotNullTerminatedResultCheck.h"
37 #include "ParentVirtualCallCheck.h"
38 #include "PosixReturnCheck.h"
39 #include "SignedCharMisuseCheck.h"
40 #include "SizeofContainerCheck.h"
41 #include "SizeofExpressionCheck.h"
42 #include "StringConstructorCheck.h"
43 #include "StringIntegerAssignmentCheck.h"
44 #include "StringLiteralWithEmbeddedNulCheck.h"
45 #include "SuspiciousEnumUsageCheck.h"
46 #include "SuspiciousMemsetUsageCheck.h"
47 #include "SuspiciousMissingCommaCheck.h"
48 #include "SuspiciousSemicolonCheck.h"
49 #include "SuspiciousStringCompareCheck.h"
50 #include "SwappedArgumentsCheck.h"
51 #include "TerminatingContinueCheck.h"
52 #include "ThrowKeywordMissingCheck.h"
53 #include "TooSmallLoopVariableCheck.h"
54 #include "UndefinedMemoryManipulationCheck.h"
55 #include "UndelegatedConstructorCheck.h"
56 #include "UnhandledSelfAssignmentCheck.h"
57 #include "UnusedRaiiCheck.h"
58 #include "UnusedReturnValueCheck.h"
59 #include "UseAfterMoveCheck.h"
60 #include "VirtualNearMissCheck.h"
61
62 namespace clang {
63 namespace tidy {
64 namespace bugprone {
65
66 class BugproneModule : public ClangTidyModule {
67 public:
68 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
69 CheckFactories.registerCheck<ArgumentCommentCheck>(
70 "bugprone-argument-comment");
71 CheckFactories.registerCheck<AssertSideEffectCheck>(
72 "bugprone-assert-side-effect");
73 CheckFactories.registerCheck<BadSignalToKillThreadCheck>(
74 "bugprone-bad-signal-to-kill-thread");
75 CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
76 "bugprone-bool-pointer-implicit-conversion");
77 CheckFactories.registerCheck<BranchCloneCheck>(
78 "bugprone-branch-clone");
79 CheckFactories.registerCheck<CopyConstructorInitCheck>(
80 "bugprone-copy-constructor-init");
81 CheckFactories.registerCheck<DanglingHandleCheck>(
82 "bugprone-dangling-handle");
83 CheckFactories.registerCheck<DynamicStaticInitializersCheck>(
84 "bugprone-dynamic-static-initializers");
85 CheckFactories.registerCheck<ExceptionEscapeCheck>(
86 "bugprone-exception-escape");
87 CheckFactories.registerCheck<FoldInitTypeCheck>(
88 "bugprone-fold-init-type");
89 CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
90 "bugprone-forward-declaration-namespace");
91 CheckFactories.registerCheck<ForwardingReferenceOverloadCheck>(
92 "bugprone-forwarding-reference-overload");
93 CheckFactories.registerCheck<InaccurateEraseCheck>(
94 "bugprone-inaccurate-erase");
95 CheckFactories.registerCheck<IncorrectRoundingsCheck>(
96 "bugprone-incorrect-roundings");
97 CheckFactories.registerCheck<InfiniteLoopCheck>(
98 "bugprone-infinite-loop");
99 CheckFactories.registerCheck<IntegerDivisionCheck>(
100 "bugprone-integer-division");
101 CheckFactories.registerCheck<LambdaFunctionNameCheck>(
102 "bugprone-lambda-function-name");
103 CheckFactories.registerCheck<MacroParenthesesCheck>(
104 "bugprone-macro-parentheses");
105 CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
106 "bugprone-macro-repeated-side-effects");
107 CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
108 "bugprone-misplaced-operator-in-strlen-in-alloc");
109 CheckFactories.registerCheck<MisplacedWideningCastCheck>(
110 "bugprone-misplaced-widening-cast");
111 CheckFactories.registerCheck<MoveForwardingReferenceCheck>(
112 "bugprone-move-forwarding-reference");
113 CheckFactories.registerCheck<MultipleStatementMacroCheck>(
114 "bugprone-multiple-statement-macro");
115 CheckFactories.registerCheck<cppcoreguidelines::NarrowingConversionsCheck>(
116 "bugprone-narrowing-conversions");
117 CheckFactories.registerCheck<NotNullTerminatedResultCheck>(
118 "bugprone-not-null-terminated-result");
119 CheckFactories.registerCheck<ParentVirtualCallCheck>(
120 "bugprone-parent-virtual-call");
121 CheckFactories.registerCheck<PosixReturnCheck>(
122 "bugprone-posix-return");
123 CheckFactories.registerCheck<SignedCharMisuseCheck>(
124 "bugprone-signed-char-misuse");
125 CheckFactories.registerCheck<SizeofContainerCheck>(
126 "bugprone-sizeof-container");
127 CheckFactories.registerCheck<SizeofExpressionCheck>(
128 "bugprone-sizeof-expression");
129 CheckFactories.registerCheck<StringConstructorCheck>(
130 "bugprone-string-constructor");
131 CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
132 "bugprone-string-integer-assignment");
133 CheckFactories.registerCheck<StringLiteralWithEmbeddedNulCheck>(
134 "bugprone-string-literal-with-embedded-nul");
135 CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
136 "bugprone-suspicious-enum-usage");
137 CheckFactories.registerCheck<SuspiciousMemsetUsageCheck>(
138 "bugprone-suspicious-memset-usage");
139 CheckFactories.registerCheck<SuspiciousMissingCommaCheck>(
140 "bugprone-suspicious-missing-comma");
141 CheckFactories.registerCheck<SuspiciousSemicolonCheck>(
142 "bugprone-suspicious-semicolon");
143 CheckFactories.registerCheck<SuspiciousStringCompareCheck>(
144 "bugprone-suspicious-string-compare");
145 CheckFactories.registerCheck<SwappedArgumentsCheck>(
146 "bugprone-swapped-arguments");
147 CheckFactories.registerCheck<TerminatingContinueCheck>(
148 "bugprone-terminating-continue");
149 CheckFactories.registerCheck<ThrowKeywordMissingCheck>(
150 "bugprone-throw-keyword-missing");
151 CheckFactories.registerCheck<TooSmallLoopVariableCheck>(
152 "bugprone-too-small-loop-variable");
153 CheckFactories.registerCheck<UndefinedMemoryManipulationCheck>(
154 "bugprone-undefined-memory-manipulation");
155 CheckFactories.registerCheck<UndelegatedConstructorCheck>(
156 "bugprone-undelegated-constructor");
157 CheckFactories.registerCheck<UnhandledSelfAssignmentCheck>(
158 "bugprone-unhandled-self-assignment");
159 CheckFactories.registerCheck<UnusedRaiiCheck>(
160 "bugprone-unused-raii");
161 CheckFactories.registerCheck<UnusedReturnValueCheck>(
162 "bugprone-unused-return-value");
163 CheckFactories.registerCheck<UseAfterMoveCheck>(
164 "bugprone-use-after-move");
165 CheckFactories.registerCheck<VirtualNearMissCheck>(
166 "bugprone-virtual-near-miss");
167 }
168 };
169
170 } // namespace bugprone
171
172 // Register the BugproneTidyModule using this statically initialized variable.
173 static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
174 X("bugprone-module", "Adds checks for bugprone code constructs.");
175
176 // This anchor is used to force the linker to link in the generated object file
177 // and thus register the BugproneModule.
178 volatile int BugproneModuleAnchorSource = 0;
179
180 } // namespace tidy
181 } // namespace clang
SuspiciousEnumUsageCheck.h
ArgumentCommentCheck.h
clang::tidy::bugprone::ForwardDeclarationNamespaceCheck
Checks if an unused forward declaration is in a wrong namespace.
Definition: ForwardDeclarationNamespaceCheck.h:40
clang::tidy::bugprone::SwappedArgumentsCheck
Finds potentially swapped arguments by looking at implicit conversions.
Definition: SwappedArgumentsCheck.h:19
clang::tidy::bugprone::AssertSideEffectCheck
Finds assert() with side effect.
Definition: AssertSideEffectCheck.h:34
clang::tidy::bugprone::SuspiciousMemsetUsageCheck
Finds memset calls with potential mistakes in their arguments.
Definition: SuspiciousMemsetUsageCheck.h:22
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:23
clang::tidy::bugprone::LambdaFunctionNameCheck
Detect when func or FUNCTION is being used from within a lambda.
Definition: LambdaFunctionNameCheck.h:24
StringIntegerAssignmentCheck.h
clang::tidy::bugprone::StringIntegerAssignmentCheck
Finds instances where an integer is assigned to a string.
Definition: StringIntegerAssignmentCheck.h:22
MacroRepeatedSideEffectsCheck.h
clang::tidy::bugprone::NotNullTerminatedResultCheck
Finds function calls where it is possible to cause a not null-terminated result.
Definition: NotNullTerminatedResultCheck.h:26
SwappedArgumentsCheck.h
clang::tidy::bugprone::SignedCharMisuseCheck
Finds signed char -> integer conversions which might indicate a programming error.
Definition: SignedCharMisuseCheck.h:28
clang::tidy::bugprone::SuspiciousEnumUsageCheck
The checker detects various cases when an enum is probably misused (as a bitmask).
Definition: SuspiciousEnumUsageCheck.h:22
clang::tidy::bugprone::SuspiciousStringCompareCheck
Find suspicious calls to string compare functions.
Definition: SuspiciousStringCompareCheck.h:22
ThrowKeywordMissingCheck.h
UndelegatedConstructorCheck.h
InaccurateEraseCheck.h
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:58
clang::tidy::bugprone::BoolPointerImplicitConversionCheck
Checks for conditions based on implicit conversion from a bool pointer to bool.
Definition: BoolPointerImplicitConversionCheck.h:29
clang::tidy::bugprone::SizeofContainerCheck
Find usages of sizeof on expressions of STL container types.
Definition: SizeofContainerCheck.h:23
clang::tidy::bugprone::UseAfterMoveCheck
The check warns if an object is used after it has been moved, without an intervening reinitialization...
Definition: UseAfterMoveCheck.h:23
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:24
clang::tidy::bugprone::BadSignalToKillThreadCheck
Finds pthread_kill function calls when thread is terminated by SIGTERM signal.
Definition: BadSignalToKillThreadCheck.h:22
UnusedRaiiCheck.h
clang::tidy::bugprone::MacroRepeatedSideEffectsCheck
Checks for repeated argument with side effects in macros.
Definition: MacroRepeatedSideEffectsCheck.h:19
clang::tidy::bugprone::MultipleStatementMacroCheck
Detect multiple statement macros that are used in unbraced conditionals.
Definition: MultipleStatementMacroCheck.h:24
clang::tidy::bugprone::ForwardingReferenceOverloadCheck
The checker looks for constructors that can act as copy or move constructors through their forwarding...
Definition: ForwardingReferenceOverloadCheck.h:29
BadSignalToKillThreadCheck.h
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:27
clang::tidy::bugprone::MisplacedWideningCastCheck
Find casts of calculation results to bigger type.
Definition: MisplacedWideningCastCheck.h:30
TooSmallLoopVariableCheck.h
clang::tidy::bugprone::StringLiteralWithEmbeddedNulCheck
Find suspicious string literals with embedded NUL characters.
Definition: StringLiteralWithEmbeddedNulCheck.h:22
BoolPointerImplicitConversionCheck.h
SizeofExpressionCheck.h
clang::tidy::bugprone::VirtualNearMissCheck
Checks for near miss of virtual methods.
Definition: VirtualNearMissCheck.h:26
clang::tidy::bugprone::MoveForwardingReferenceCheck
The check warns if std::move is applied to a forwarding reference (i.e.
Definition: MoveForwardingReferenceCheck.h:36
MisplacedOperatorInStrlenInAllocCheck.h
SuspiciousStringCompareCheck.h
CopyConstructorInitCheck.h
MultipleStatementMacroCheck.h
MacroParenthesesCheck.h
clang::tidy::bugprone::BugproneModule
Definition: BugproneTidyModule.cpp:66
UndefinedMemoryManipulationCheck.h
clang::tidy::bugprone::DanglingHandleCheck
Detect dangling references in value handlers like std::experimental::string_view. ...
Definition: DanglingHandleCheck.h:23
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:80
clang::tidy::bugprone::UnhandledSelfAssignmentCheck
Finds user-defined copy assignment operators which do not protect the code against self-assignment ei...
Definition: UnhandledSelfAssignmentCheck.h:24
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:23
StringConstructorCheck.h
clang::tidy::bugprone::StringConstructorCheck
Finds suspicious string constructor and check their parameters.
Definition: StringConstructorCheck.h:22
clang::tidy::bugprone::IncorrectRoundingsCheck
Checks the usage of patterns known to produce incorrect rounding.
Definition: IncorrectRoundingsCheck.h:26
MisplacedWideningCastCheck.h
BranchCloneCheck.h
LambdaFunctionNameCheck.h
clang::tidy::bugprone::SizeofExpressionCheck
Find suspicious usages of sizeof expression.
Definition: SizeofExpressionCheck.h:22
clang::tidy::bugprone::ParentVirtualCallCheck
Finds calls to grand..-parent virtual methods instead of parent&#39;s.
Definition: ParentVirtualCallCheck.h:22
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:31
DanglingHandleCheck.h
NotNullTerminatedResultCheck.h
SignedCharMisuseCheck.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:23
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:30
clang::tidy::bugprone::InaccurateEraseCheck
Checks for inaccurate use of the erase() method.
Definition: InaccurateEraseCheck.h:25
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:68
clang::tidy::BugproneModuleAnchorSource
volatile int BugproneModuleAnchorSource
Definition: BugproneTidyModule.cpp:178
ExceptionEscapeCheck.h
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: bugprone/ExceptionEscapeCheck.h:27
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
SuspiciousSemicolonCheck.h
IntegerDivisionCheck.h
clang::tidy::cppcoreguidelines::NarrowingConversionsCheck
Checks for narrowing conversions, e.g: int i = 0; i += 0.1;.
Definition: NarrowingConversionsCheck.h:24
InfiniteLoopCheck.h
clang::tidy::bugprone::InfiniteLoopCheck
Finds obvious infinite loops (loops where the condition variable is not changed at all)...
Definition: InfiniteLoopCheck.h:23
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:23
clang::tidy::bugprone::TerminatingContinueCheck
Checks if a &#39;continue&#39; statement terminates the loop (i.e.
Definition: TerminatingContinueCheck.h:23
clang::tidy::bugprone::SuspiciousSemicolonCheck
This check finds semicolon that modifies the meaning of the program unintendedly. ...
Definition: SuspiciousSemicolonCheck.h:23
UnhandledSelfAssignmentCheck.h
PosixReturnCheck.h
clang::tidy::bugprone::SuspiciousMissingCommaCheck
This check finds string literals which are probably concatenated accidentally.
Definition: SuspiciousMissingCommaCheck.h:23
DynamicStaticInitializersCheck.h
UseAfterMoveCheck.h
clang::tidy::bugprone::BranchCloneCheck
A check for detecting if/else if/else chains where two or more branches are Type I clones of each oth...
Definition: BranchCloneCheck.h:27
clang::tidy::bugprone::UnusedRaiiCheck
Finds temporaries that look like RAII objects.
Definition: UnusedRaiiCheck.h:22
clang::tidy::bugprone::UnusedReturnValueCheck
Detects function calls where the return value is unused.
Definition: UnusedReturnValueCheck.h:23
ForwardDeclarationNamespaceCheck.h
clang::tidy::bugprone::DynamicStaticInitializersCheck
Finds dynamically initialized static variables in header files.
Definition: DynamicStaticInitializersCheck.h:27
SuspiciousMemsetUsageCheck.h
UnusedReturnValueCheck.h
SuspiciousMissingCommaCheck.h
StringLiteralWithEmbeddedNulCheck.h
clang::tidy::bugprone::PosixReturnCheck
Definition: PosixReturnCheck.h:18
FoldInitTypeCheck.h
TerminatingContinueCheck.h
clang::tidy::bugprone::UndefinedMemoryManipulationCheck
Finds calls of memory manipulation functions memset(), memcpy() and memmove() on not TriviallyCopyabl...
Definition: UndefinedMemoryManipulationCheck.h:24
MoveForwardingReferenceCheck.h