clang-tools 19.0.0git
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"
18#include "BranchCloneCheck.h"
24#include "DanglingHandleCheck.h"
27#include "EmptyCatchCheck.h"
29#include "FoldInitTypeCheck.h"
37#include "InfiniteLoopCheck.h"
49#include "NoEscapeCheck.h"
54#include "PosixReturnCheck.h"
58#include "SignalHandlerCheck.h"
90#include "UnusedRaiiCheck.h"
92#include "UseAfterMoveCheck.h"
94
95namespace clang::tidy {
96namespace bugprone {
97
99public:
100 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
101 CheckFactories.registerCheck<ArgumentCommentCheck>(
102 "bugprone-argument-comment");
103 CheckFactories.registerCheck<AssertSideEffectCheck>(
104 "bugprone-assert-side-effect");
106 "bugprone-assignment-in-if-condition");
108 "bugprone-bad-signal-to-kill-thread");
110 "bugprone-bool-pointer-implicit-conversion");
111 CheckFactories.registerCheck<BranchCloneCheck>("bugprone-branch-clone");
113 "bugprone-casting-through-void");
115 "bugprone-chained-comparison");
117 "bugprone-compare-pointer-to-member-virtual-function");
119 "bugprone-copy-constructor-init");
120 CheckFactories.registerCheck<DanglingHandleCheck>(
121 "bugprone-dangling-handle");
123 "bugprone-dynamic-static-initializers");
125 "bugprone-easily-swappable-parameters");
126 CheckFactories.registerCheck<EmptyCatchCheck>("bugprone-empty-catch");
127 CheckFactories.registerCheck<ExceptionEscapeCheck>(
128 "bugprone-exception-escape");
129 CheckFactories.registerCheck<FoldInitTypeCheck>("bugprone-fold-init-type");
131 "bugprone-forward-declaration-namespace");
133 "bugprone-forwarding-reference-overload");
135 "bugprone-implicit-widening-of-multiplication-result");
136 CheckFactories.registerCheck<InaccurateEraseCheck>(
137 "bugprone-inaccurate-erase");
139 "bugprone-incorrect-enable-if");
141 "bugprone-switch-missing-default-case");
143 "bugprone-inc-dec-in-conditions");
145 "bugprone-incorrect-roundings");
146 CheckFactories.registerCheck<InfiniteLoopCheck>("bugprone-infinite-loop");
147 CheckFactories.registerCheck<IntegerDivisionCheck>(
148 "bugprone-integer-division");
150 "bugprone-lambda-function-name");
151 CheckFactories.registerCheck<MacroParenthesesCheck>(
152 "bugprone-macro-parentheses");
154 "bugprone-macro-repeated-side-effects");
156 "bugprone-misplaced-operator-in-strlen-in-alloc");
158 "bugprone-misplaced-pointer-arithmetic-in-alloc");
160 "bugprone-misplaced-widening-cast");
162 "bugprone-move-forwarding-reference");
164 "bugprone-multi-level-implicit-pointer-conversion");
166 "bugprone-multiple-new-in-one-expression");
168 "bugprone-multiple-statement-macro");
170 "bugprone-optional-value-conversion");
172 "bugprone-redundant-branch-condition");
174 "bugprone-narrowing-conversions");
175 CheckFactories.registerCheck<NoEscapeCheck>("bugprone-no-escape");
177 "bugprone-non-zero-enum-to-bool-conversion");
179 "bugprone-not-null-terminated-result");
181 "bugprone-parent-virtual-call");
182 CheckFactories.registerCheck<PosixReturnCheck>("bugprone-posix-return");
184 "bugprone-reserved-identifier");
186 "bugprone-shared-ptr-array-mismatch");
187 CheckFactories.registerCheck<SignalHandlerCheck>("bugprone-signal-handler");
188 CheckFactories.registerCheck<SignedCharMisuseCheck>(
189 "bugprone-signed-char-misuse");
190 CheckFactories.registerCheck<SizeofContainerCheck>(
191 "bugprone-sizeof-container");
192 CheckFactories.registerCheck<SizeofExpressionCheck>(
193 "bugprone-sizeof-expression");
195 "bugprone-spuriously-wake-up-functions");
196 CheckFactories.registerCheck<StandaloneEmptyCheck>(
197 "bugprone-standalone-empty");
199 "bugprone-string-constructor");
201 "bugprone-string-integer-assignment");
203 "bugprone-string-literal-with-embedded-nul");
205 "bugprone-stringview-nullptr");
207 "bugprone-suspicious-enum-usage");
209 "bugprone-suspicious-include");
211 "bugprone-suspicious-memory-comparison");
213 "bugprone-suspicious-memset-usage");
215 "bugprone-suspicious-missing-comma");
217 "bugprone-suspicious-realloc-usage");
219 "bugprone-suspicious-semicolon");
221 "bugprone-suspicious-string-compare");
223 "bugprone-suspicious-stringview-data-usage");
224 CheckFactories.registerCheck<SwappedArgumentsCheck>(
225 "bugprone-swapped-arguments");
227 "bugprone-terminating-continue");
229 "bugprone-throw-keyword-missing");
231 "bugprone-too-small-loop-variable");
233 "bugprone-unchecked-optional-access");
235 "bugprone-undefined-memory-manipulation");
237 "bugprone-undelegated-constructor");
239 "bugprone-unhandled-self-assignment");
241 "bugprone-unhandled-exception-at-new");
243 "bugprone-unique-ptr-array-mismatch");
245 "bugprone-crtp-constructor-accessibility");
246 CheckFactories.registerCheck<UnsafeFunctionsCheck>(
247 "bugprone-unsafe-functions");
249 "bugprone-unused-local-non-trivial-variable");
250 CheckFactories.registerCheck<UnusedRaiiCheck>("bugprone-unused-raii");
252 "bugprone-unused-return-value");
253 CheckFactories.registerCheck<UseAfterMoveCheck>("bugprone-use-after-move");
254 CheckFactories.registerCheck<VirtualNearMissCheck>(
255 "bugprone-virtual-near-miss");
256 }
257};
258
259} // namespace bugprone
260
261// Register the BugproneTidyModule using this statically initialized variable.
262static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
263 X("bugprone-module", "Adds checks for bugprone code constructs.");
264
265// This anchor is used to force the linker to link in the generated object file
266// and thus register the BugproneModule.
268
269} // namespace clang::tidy
int X
A collection of ClangTidyCheckFactory instances.
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Checks that argument comments match parameter names.
Catches assignments within the condition clause of an if statement.
Finds pthread_kill function calls when thread is terminated by SIGTERM signal.
Checks for conditions based on implicit conversion from a bool pointer to bool.
A check for detecting if/else if/else chains where two or more branches are Type I clones of each oth...
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
Detects unsafe or redundant two-step casting operations involving void*.
Check detects chained comparison operators that can lead to unintended behavior or logical errors.
Detects unspecified behavior about equality comparison between pointer to member virtual function and...
Finds copy constructors where the ctor don't call the copy constructor of the base class.
Detects error-prone Curiously Recurring Template Pattern usage, when the CRTP can be constructed outs...
Detect dangling references in value handlers like std::experimental::string_view.
Finds dynamically initialized static variables in header files.
Finds function definitions where parameters of convertible types follow each other directly,...
Detects and suggests addressing issues with empty catch statements.
Finds functions which should not throw exceptions: Destructors, move constructors,...
Find and flag invalid initializer values in folds, e.g.
Checks if an unused forward declaration is in a wrong namespace.
The checker looks for constructors that can act as copy or move constructors through their forwarding...
Diagnoses instances of an implicit widening of multiplication result.
Checks for inaccurate use of the erase() method.
Detects when a variable is both incremented/decremented and referenced inside a complex condition and...
Detects incorrect usages of std::enable_if that don't name the nested type type.
Checks the usage of patterns known to produce incorrect rounding.
Finds obvious infinite loops (loops where the condition variable is not changed at all).
Finds cases where integer division in a floating point context is likely to cause unintended loss of ...
Detect when func or FUNCTION is being used from within a lambda.
Finds macros that can have unexpected behaviour due to missing parentheses.
Checks for repeated argument with side effects in macros.
Finds cases where 1 is added to the string in the argument to a function in the strlen() family inste...
Finds cases where an integer is added to or subracted from the result of a memory allocation function...
Find casts of calculation results to bigger type.
The check warns if std::move is applied to a forwarding reference (i.e.
Detects implicit conversions between pointers of different levels of indirection.
For the user-facing documentation see: http://clang.llvm.org/extra/clang-tidy/checks/bugprone/multipl...
Detect multiple statement macros that are used in unbraced conditionals.
Block arguments in dispatch_async() and dispatch_after() are guaranteed to escape.
Definition: NoEscapeCheck.h:22
Detect implicit and explicit casts of enum type into bool where enum type doesn't have a zero-value e...
Finds function calls where it is possible to cause a not null-terminated result.
Detects potentially unintentional and redundant conversions where a value is extracted from an option...
Finds calls to grand..-parent virtual methods instead of parent's.
Finds condition variables in nested if statements that were also checked in the outer if statement an...
Checks for usages of identifiers reserved for use by the implementation.
Find std::shared_ptr<T>(new T[...]), replace it (if applicable) with std::shared_ptr<T[]>(new T[....
Checker for signal handler functions.
Finds those signed char -> integer conversions which might indicate a programming error.
Find usages of sizeof on expressions of STL container types.
Find suspicious usages of sizeof expression.
Finds cnd_wait, cnd_timedwait, wait, wait_for, or wait_until function calls when the function is not ...
Checks for ignored calls to empty() on a range and suggests clear() as an alternative if it is an exi...
Finds suspicious string constructor and check their parameters.
Finds instances where an integer is assigned to a string.
Find suspicious string literals with embedded NUL characters.
Checks for various ways that the const CharT* constructor of std::basic_string_view can be passed a n...
The checker detects various cases when an enum is probably misused (as a bitmask).
Warns on inclusion of files whose names suggest that they're implementation files,...
Finds potentially incorrect calls to memcmp() based on properties of the arguments.
Finds memset calls with potential mistakes in their arguments.
This check finds string literals which are probably concatenated accidentally.
Finds usages of realloc where the return value is assigned to the same variable as passed to the firs...
This check finds semicolon that modifies the meaning of the program unintendedly.
Find suspicious calls to string compare functions.
Identifies suspicious usages of std::string_view::data() that could lead to reading out-of-bounds dat...
Finds potentially swapped arguments by looking at implicit conversions.
Ensures that switch statements without default cases are flagged, focuses only on covering cases with...
Checks if a 'continue' statement terminates the loop (i.e.
Emits a warning about temporary objects whose type is (or is derived from) a class that has 'EXCEPTIO...
This check gives a warning if a loop variable has a too small type which might not be able to represe...
Warns when the code is unwrapping a std::optional<T>, absl::optional<T>, or base::std::optional<T> ob...
Finds calls of memory manipulation functions memset(), memcpy() and memmove() on non-TriviallyCopyabl...
Finds creation of temporary objects in constructors that look like a function call to another constru...
Finds calls to 'new' that may throw unhandled exception at allocation failure.
Finds user-defined copy assignment operators which do not protect the code against self-assignment ei...
Finds initializations of C++ unique pointers to non-array type that are initialized with an array.
Checks for functions that have safer, more secure replacements available, or are considered deprecate...
Warns when a local non trivial variable is unused within a function.
Finds temporaries that look like RAII objects.
Detects function calls where the return value is unused.
The check warns if an object is used after it has been moved, without an intervening reinitialization...
Checks for near miss of virtual methods.
Checks for narrowing conversions, e.g: int i = 0; i += 0.1;.
volatile int BugproneModuleAnchorSource