clang-tools 17.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"
20#include "DanglingHandleCheck.h"
24#include "FoldInitTypeCheck.h"
30#include "InfiniteLoopCheck.h"
41#include "NoEscapeCheck.h"
45#include "PosixReturnCheck.h"
49#include "SignalHandlerCheck.h"
78#include "UnusedRaiiCheck.h"
80#include "UseAfterMoveCheck.h"
82
83namespace clang::tidy {
84namespace bugprone {
85
87public:
88 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
89 CheckFactories.registerCheck<ArgumentCommentCheck>(
90 "bugprone-argument-comment");
92 "bugprone-assert-side-effect");
94 "bugprone-assignment-in-if-condition");
96 "bugprone-bad-signal-to-kill-thread");
98 "bugprone-bool-pointer-implicit-conversion");
99 CheckFactories.registerCheck<BranchCloneCheck>("bugprone-branch-clone");
101 "bugprone-copy-constructor-init");
102 CheckFactories.registerCheck<DanglingHandleCheck>(
103 "bugprone-dangling-handle");
105 "bugprone-dynamic-static-initializers");
107 "bugprone-easily-swappable-parameters");
108 CheckFactories.registerCheck<ExceptionEscapeCheck>(
109 "bugprone-exception-escape");
110 CheckFactories.registerCheck<FoldInitTypeCheck>("bugprone-fold-init-type");
112 "bugprone-forward-declaration-namespace");
114 "bugprone-forwarding-reference-overload");
116 "bugprone-implicit-widening-of-multiplication-result");
117 CheckFactories.registerCheck<InaccurateEraseCheck>(
118 "bugprone-inaccurate-erase");
120 "bugprone-incorrect-roundings");
121 CheckFactories.registerCheck<InfiniteLoopCheck>("bugprone-infinite-loop");
122 CheckFactories.registerCheck<IntegerDivisionCheck>(
123 "bugprone-integer-division");
125 "bugprone-lambda-function-name");
126 CheckFactories.registerCheck<MacroParenthesesCheck>(
127 "bugprone-macro-parentheses");
129 "bugprone-macro-repeated-side-effects");
131 "bugprone-misplaced-operator-in-strlen-in-alloc");
133 "bugprone-misplaced-pointer-arithmetic-in-alloc");
135 "bugprone-misplaced-widening-cast");
137 "bugprone-move-forwarding-reference");
139 "bugprone-multiple-new-in-one-expression");
141 "bugprone-multiple-statement-macro");
143 "bugprone-redundant-branch-condition");
145 "bugprone-narrowing-conversions");
146 CheckFactories.registerCheck<NoEscapeCheck>("bugprone-no-escape");
148 "bugprone-non-zero-enum-to-bool-conversion");
150 "bugprone-not-null-terminated-result");
152 "bugprone-parent-virtual-call");
153 CheckFactories.registerCheck<PosixReturnCheck>("bugprone-posix-return");
155 "bugprone-reserved-identifier");
157 "bugprone-shared-ptr-array-mismatch");
158 CheckFactories.registerCheck<SignalHandlerCheck>("bugprone-signal-handler");
159 CheckFactories.registerCheck<SignedCharMisuseCheck>(
160 "bugprone-signed-char-misuse");
161 CheckFactories.registerCheck<SizeofContainerCheck>(
162 "bugprone-sizeof-container");
163 CheckFactories.registerCheck<SizeofExpressionCheck>(
164 "bugprone-sizeof-expression");
166 "bugprone-spuriously-wake-up-functions");
167 CheckFactories.registerCheck<StandaloneEmptyCheck>(
168 "bugprone-standalone-empty");
170 "bugprone-string-constructor");
172 "bugprone-string-integer-assignment");
174 "bugprone-string-literal-with-embedded-nul");
176 "bugprone-stringview-nullptr");
178 "bugprone-suspicious-enum-usage");
180 "bugprone-suspicious-include");
182 "bugprone-suspicious-memory-comparison");
184 "bugprone-suspicious-memset-usage");
186 "bugprone-suspicious-missing-comma");
188 "bugprone-suspicious-realloc-usage");
190 "bugprone-suspicious-semicolon");
192 "bugprone-suspicious-string-compare");
193 CheckFactories.registerCheck<SwappedArgumentsCheck>(
194 "bugprone-swapped-arguments");
196 "bugprone-terminating-continue");
198 "bugprone-throw-keyword-missing");
200 "bugprone-too-small-loop-variable");
202 "bugprone-unchecked-optional-access");
204 "bugprone-undefined-memory-manipulation");
206 "bugprone-undelegated-constructor");
208 "bugprone-unhandled-self-assignment");
210 "bugprone-unhandled-exception-at-new");
212 "bugprone-unique-ptr-array-mismatch");
213 CheckFactories.registerCheck<UnsafeFunctionsCheck>(
214 "bugprone-unsafe-functions");
215 CheckFactories.registerCheck<UnusedRaiiCheck>("bugprone-unused-raii");
217 "bugprone-unused-return-value");
218 CheckFactories.registerCheck<UseAfterMoveCheck>("bugprone-use-after-move");
219 CheckFactories.registerCheck<VirtualNearMissCheck>(
220 "bugprone-virtual-near-miss");
221 }
222};
223
224} // namespace bugprone
225
226// Register the BugproneTidyModule using this statically initialized variable.
227static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
228 X("bugprone-module", "Adds checks for bugprone code constructs.");
229
230// This anchor is used to force the linker to link in the generated object file
231// and thus register the BugproneModule.
233
234} // 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.
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,...
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.
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.
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.
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.
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 not 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