clang-tools  5.0.0
MiscTidyModule.cpp
Go to the documentation of this file.
1 //===--- MiscTidyModule.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 "ArgumentCommentCheck.h"
14 #include "AssertSideEffectCheck.h"
16 #include "DanglingHandleCheck.h"
18 #include "FoldInitTypeCheck.h"
21 #include "InaccurateEraseCheck.h"
22 #include "IncorrectRoundings.h"
25 #include "MacroParenthesesCheck.h"
27 #include "MisplacedConstCheck.h"
35 #include "NonCopyableObjects.h"
37 #include "SizeofContainerCheck.h"
38 #include "SizeofExpressionCheck.h"
39 #include "StaticAssertCheck.h"
40 #include "StringCompareCheck.h"
41 #include "StringConstructorCheck.h"
48 #include "SwappedArgumentsCheck.h"
51 #include "UndelegatedConstructor.h"
53 #include "UnusedAliasDeclsCheck.h"
54 #include "UnusedParametersCheck.h"
55 #include "UnusedRAIICheck.h"
56 #include "UnusedUsingDeclsCheck.h"
57 #include "UseAfterMoveCheck.h"
58 #include "VirtualNearMissCheck.h"
59 
60 namespace clang {
61 namespace tidy {
62 namespace misc {
63 
64 class MiscModule : public ClangTidyModule {
65 public:
66  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
67  CheckFactories.registerCheck<ArgumentCommentCheck>("misc-argument-comment");
68  CheckFactories.registerCheck<AssertSideEffectCheck>(
69  "misc-assert-side-effect");
71  "misc-forwarding-reference-overload");
72  CheckFactories.registerCheck<LambdaFunctionNameCheck>(
73  "misc-lambda-function-name");
74  CheckFactories.registerCheck<MisplacedConstCheck>("misc-misplaced-const");
76  "misc-unconventional-assign-operator");
78  "misc-bool-pointer-implicit-conversion");
79  CheckFactories.registerCheck<DanglingHandleCheck>("misc-dangling-handle");
81  "misc-definitions-in-headers");
82  CheckFactories.registerCheck<FoldInitTypeCheck>("misc-fold-init-type");
84  "misc-forward-declaration-namespace");
85  CheckFactories.registerCheck<InaccurateEraseCheck>("misc-inaccurate-erase");
86  CheckFactories.registerCheck<IncorrectRoundings>(
87  "misc-incorrect-roundings");
89  "misc-inefficient-algorithm");
90  CheckFactories.registerCheck<MacroParenthesesCheck>(
91  "misc-macro-parentheses");
93  "misc-macro-repeated-side-effects");
95  "misc-misplaced-widening-cast");
97  "misc-move-const-arg");
99  "misc-move-constructor-init");
101  "misc-move-forwarding-reference");
103  "misc-multiple-statement-macro");
104  CheckFactories.registerCheck<NewDeleteOverloadsCheck>(
105  "misc-new-delete-overloads");
107  "misc-noexcept-move-constructor");
108  CheckFactories.registerCheck<NonCopyableObjectsCheck>(
109  "misc-non-copyable-objects");
110  CheckFactories.registerCheck<RedundantExpressionCheck>(
111  "misc-redundant-expression");
112  CheckFactories.registerCheck<SizeofContainerCheck>("misc-sizeof-container");
113  CheckFactories.registerCheck<SizeofExpressionCheck>(
114  "misc-sizeof-expression");
115  CheckFactories.registerCheck<StaticAssertCheck>("misc-static-assert");
116  CheckFactories.registerCheck<StringCompareCheck>("misc-string-compare");
117  CheckFactories.registerCheck<StringConstructorCheck>(
118  "misc-string-constructor");
120  "misc-string-integer-assignment");
122  "misc-string-literal-with-embedded-nul");
123  CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
124  "misc-suspicious-enum-usage");
126  "misc-suspicious-missing-comma");
127  CheckFactories.registerCheck<SuspiciousSemicolonCheck>(
128  "misc-suspicious-semicolon");
130  "misc-suspicious-string-compare");
131  CheckFactories.registerCheck<SwappedArgumentsCheck>(
132  "misc-swapped-arguments");
134  "misc-throw-by-value-catch-by-reference");
136  "misc-undelegated-constructor");
138  "misc-uniqueptr-reset-release");
139  CheckFactories.registerCheck<UnusedAliasDeclsCheck>(
140  "misc-unused-alias-decls");
141  CheckFactories.registerCheck<UnusedParametersCheck>(
142  "misc-unused-parameters");
143  CheckFactories.registerCheck<UnusedRAIICheck>("misc-unused-raii");
144  CheckFactories.registerCheck<UnusedUsingDeclsCheck>(
145  "misc-unused-using-decls");
146  CheckFactories.registerCheck<UseAfterMoveCheck>("misc-use-after-move");
147  CheckFactories.registerCheck<VirtualNearMissCheck>(
148  "misc-virtual-near-miss");
149  }
150 };
151 
152 } // namespace misc
153 
154 // Register the MiscTidyModule using this statically initialized variable.
155 static ClangTidyModuleRegistry::Add<misc::MiscModule>
156  X("misc-module", "Adds miscellaneous lint checks.");
157 
158 // This anchor is used to force the linker to link in the generated object file
159 // and thus register the MiscModule.
160 volatile int MiscModuleAnchorSource = 0;
161 
162 } // namespace tidy
163 } // namespace clang
This check diagnoses when a const qualifier is applied to a typedef to a pointer type rather than to ...
Finds instances where an integer is assigned to a string.
Checks for repeated argument with side effects in macros.
Finds potentially swapped arguments by looking at implicit conversions.
Find and replace unique_ptr::reset(release()) with std::move().
Checks for conditions based on implicit conversion from a bool pointer to bool.
checks for locations that do not throw by value
Finds temporaries that look like RAII objects.
Finds creation of temporary objects in constructors that look like a function call to another constru...
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Replaces assert() with static_assert() if the condition is evaluatable at compile time...
Finds unused namespace alias declarations.
Find suspicious calls to string compare functions.
Checks for near miss of virtual methods.
Checks the usage of patterns known to produce incorrect rounding.
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module...
A collection of ClangTidyCheckFactory instances.
Finds unused using declarations.
Find suspicious string literals with embedded NUL characters.
This check finds string literals which are probably concatenated accidentally.
Find suspicious usages of sizeof expression.
Finds macros that can have unexpected behaviour due to missing parentheses.
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Detect multiple statement macros that are used in unbraced conditionals.
The check flags dereferences and non-pointer declarations of objects that are not meant to be passed ...
The check warns if std::move is applied to a forwarding reference (i.e.
The check flags user-defined move constructors and assignment operators not marked with noexcept or m...
Finds suspicious string constructor and check their parameters.
Detect when func or FUNCTION is being used from within a lambda.
Find casts of calculation results to bigger type.
Detect useless or suspicious redundant expressions.
This check flags all calls compare when used to check for string equality or inequality.
Finds assert() with side effect.
The check flags user-defined move constructors that have a ctor-initializer initializing a member or ...
Detect dangling references in value handlers like std::experimental::string_view. ...
The checker looks for constructors that can act as copy or move constructors through their forwarding...
The checker detects various cases when an enum is probably misused (as a bitmask).
volatile int MiscModuleAnchorSource
Find usages of sizeof on expressions of STL container types.
Finds non-extern non-inline function and variable definitions in header files, which can lead to pote...
Find and flag invalid initializer values in folds, e.g.
Checks if an unused forward declaration is in a wrong namespace.
Finds declarations of assignment operators with the wrong return and/or argument types and definition...
Finds unused parameters and fixes them, so that -Wunused-parameter can be turned on.
static ClangTidyModuleRegistry::Add< bugprone::BugproneModule > X("bugprone-module","Adds checks for bugprone code constructs.")
This check finds semicolon that modifies the meaning of the program unintendedly. ...
Checks for inaccurate use of the erase() method.
Warns on inefficient use of STL algorithms on associative containers.
The check warns if an object is used after it has been moved, without an intervening reinitialization...