clang-tools 18.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"
22#include "DanglingHandleCheck.h"
25#include "EmptyCatchCheck.h"
27#include "FoldInitTypeCheck.h"
35#include "InfiniteLoopCheck.h"
47#include "NoEscapeCheck.h"
52#include "PosixReturnCheck.h"
56#include "SignalHandlerCheck.h"
86#include "UnusedRaiiCheck.h"
88#include "UseAfterMoveCheck.h"
90
91namespace clang::tidy {
92namespace bugprone {
93
95public:
96 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
97 CheckFactories.registerCheck<ArgumentCommentCheck>(
98 "bugprone-argument-comment");
100 "bugprone-assert-side-effect");
102 "bugprone-assignment-in-if-condition");
104 "bugprone-bad-signal-to-kill-thread");
106 "bugprone-bool-pointer-implicit-conversion");
107 CheckFactories.registerCheck<BranchCloneCheck>("bugprone-branch-clone");
109 "bugprone-casting-through-void");
111 "bugprone-compare-pointer-to-member-virtual-function");
113 "bugprone-copy-constructor-init");
114 CheckFactories.registerCheck<DanglingHandleCheck>(
115 "bugprone-dangling-handle");
117 "bugprone-dynamic-static-initializers");
119 "bugprone-easily-swappable-parameters");
120 CheckFactories.registerCheck<EmptyCatchCheck>("bugprone-empty-catch");
121 CheckFactories.registerCheck<ExceptionEscapeCheck>(
122 "bugprone-exception-escape");
123 CheckFactories.registerCheck<FoldInitTypeCheck>("bugprone-fold-init-type");
125 "bugprone-forward-declaration-namespace");
127 "bugprone-forwarding-reference-overload");
129 "bugprone-implicit-widening-of-multiplication-result");
130 CheckFactories.registerCheck<InaccurateEraseCheck>(
131 "bugprone-inaccurate-erase");
133 "bugprone-incorrect-enable-if");
135 "bugprone-switch-missing-default-case");
137 "bugprone-inc-dec-in-conditions");
139 "bugprone-incorrect-roundings");
140 CheckFactories.registerCheck<InfiniteLoopCheck>("bugprone-infinite-loop");
141 CheckFactories.registerCheck<IntegerDivisionCheck>(
142 "bugprone-integer-division");
144 "bugprone-lambda-function-name");
145 CheckFactories.registerCheck<MacroParenthesesCheck>(
146 "bugprone-macro-parentheses");
148 "bugprone-macro-repeated-side-effects");
150 "bugprone-misplaced-operator-in-strlen-in-alloc");
152 "bugprone-misplaced-pointer-arithmetic-in-alloc");
154 "bugprone-misplaced-widening-cast");
156 "bugprone-move-forwarding-reference");
158 "bugprone-multi-level-implicit-pointer-conversion");
160 "bugprone-multiple-new-in-one-expression");
162 "bugprone-multiple-statement-macro");
164 "bugprone-optional-value-conversion");
166 "bugprone-redundant-branch-condition");
168 "bugprone-narrowing-conversions");
169 CheckFactories.registerCheck<NoEscapeCheck>("bugprone-no-escape");
171 "bugprone-non-zero-enum-to-bool-conversion");
173 "bugprone-not-null-terminated-result");
175 "bugprone-parent-virtual-call");
176 CheckFactories.registerCheck<PosixReturnCheck>("bugprone-posix-return");
178 "bugprone-reserved-identifier");
180 "bugprone-shared-ptr-array-mismatch");
181 CheckFactories.registerCheck<SignalHandlerCheck>("bugprone-signal-handler");
182 CheckFactories.registerCheck<SignedCharMisuseCheck>(
183 "bugprone-signed-char-misuse");
184 CheckFactories.registerCheck<SizeofContainerCheck>(
185 "bugprone-sizeof-container");
186 CheckFactories.registerCheck<SizeofExpressionCheck>(
187 "bugprone-sizeof-expression");
189 "bugprone-spuriously-wake-up-functions");
190 CheckFactories.registerCheck<StandaloneEmptyCheck>(
191 "bugprone-standalone-empty");
193 "bugprone-string-constructor");
195 "bugprone-string-integer-assignment");
197 "bugprone-string-literal-with-embedded-nul");
199 "bugprone-stringview-nullptr");
201 "bugprone-suspicious-enum-usage");
203 "bugprone-suspicious-include");
205 "bugprone-suspicious-memory-comparison");
207 "bugprone-suspicious-memset-usage");
209 "bugprone-suspicious-missing-comma");
211 "bugprone-suspicious-realloc-usage");
213 "bugprone-suspicious-semicolon");
215 "bugprone-suspicious-string-compare");
216 CheckFactories.registerCheck<SwappedArgumentsCheck>(
217 "bugprone-swapped-arguments");
219 "bugprone-terminating-continue");
221 "bugprone-throw-keyword-missing");
223 "bugprone-too-small-loop-variable");
225 "bugprone-unchecked-optional-access");
227 "bugprone-undefined-memory-manipulation");
229 "bugprone-undelegated-constructor");
231 "bugprone-unhandled-self-assignment");
233 "bugprone-unhandled-exception-at-new");
235 "bugprone-unique-ptr-array-mismatch");
236 CheckFactories.registerCheck<UnsafeFunctionsCheck>(
237 "bugprone-unsafe-functions");
238 CheckFactories.registerCheck<UnusedRaiiCheck>("bugprone-unused-raii");
240 "bugprone-unused-return-value");
241 CheckFactories.registerCheck<UseAfterMoveCheck>("bugprone-use-after-move");
242 CheckFactories.registerCheck<VirtualNearMissCheck>(
243 "bugprone-virtual-near-miss");
244 }
245};
246
247} // namespace bugprone
248
249// Register the BugproneTidyModule using this statically initialized variable.
250static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
251 X("bugprone-module", "Adds checks for bugprone code constructs.");
252
253// This anchor is used to force the linker to link in the generated object file
254// and thus register the BugproneModule.
256
257} // 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*.
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.
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.
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...
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