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