clang-tools 22.0.0git
ModernizeTidyModule.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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"
12#include "AvoidBindCheck.h"
13#include "AvoidCArraysCheck.h"
19#include "LoopConvertCheck.h"
20#include "MacroToEnumCheck.h"
21#include "MakeSharedCheck.h"
22#include "MakeUniqueCheck.h"
24#include "PassByValueCheck.h"
27#include "ReplaceAutoPtrCheck.h"
31#include "ShrinkToFitCheck.h"
32#include "TypeTraitsCheck.h"
34#include "UseAutoCheck.h"
36#include "UseConstraintsCheck.h"
39#include "UseEmplaceCheck.h"
43#include "UseNodiscardCheck.h"
44#include "UseNoexceptCheck.h"
45#include "UseNullptrCheck.h"
46#include "UseOverrideCheck.h"
47#include "UseRangesCheck.h"
48#include "UseScopedLockCheck.h"
50#include "UseStdFormatCheck.h"
51#include "UseStdNumbersCheck.h"
52#include "UseStdPrintCheck.h"
56#include "UseUsingCheck.h"
57
58using namespace clang::ast_matchers;
59
60namespace clang::tidy {
61namespace modernize {
62
64public:
65 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
66 CheckFactories.registerCheck<AvoidBindCheck>("modernize-avoid-bind");
67 CheckFactories.registerCheck<AvoidCArraysCheck>("modernize-avoid-c-arrays");
69 "modernize-avoid-setjmp-longjmp");
71 "modernize-avoid-variadic-functions");
73 "modernize-concat-nested-namespaces");
75 "modernize-deprecated-headers");
77 "modernize-deprecated-ios-base-aliases");
78 CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert");
79 CheckFactories.registerCheck<MacroToEnumCheck>("modernize-macro-to-enum");
80 CheckFactories.registerCheck<MakeSharedCheck>("modernize-make-shared");
81 CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique");
83 "modernize-min-max-use-initializer-list");
84 CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value");
86 "modernize-use-designated-initializers");
88 "modernize-use-integer-sign-comparison");
89 CheckFactories.registerCheck<UseRangesCheck>("modernize-use-ranges");
90 CheckFactories.registerCheck<UseScopedLockCheck>(
91 "modernize-use-scoped-lock");
93 "modernize-use-starts-ends-with");
94 CheckFactories.registerCheck<UseStdFormatCheck>("modernize-use-std-format");
95 CheckFactories.registerCheck<UseStdNumbersCheck>(
96 "modernize-use-std-numbers");
97 CheckFactories.registerCheck<UseStdPrintCheck>("modernize-use-std-print");
99 "modernize-raw-string-literal");
100 CheckFactories.registerCheck<RedundantVoidArgCheck>(
101 "modernize-redundant-void-arg");
102 CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
103 "modernize-replace-auto-ptr");
105 "modernize-replace-disallow-copy-and-assign-macro");
107 "modernize-replace-random-shuffle");
109 "modernize-return-braced-init-list");
110 CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit");
111 CheckFactories.registerCheck<TypeTraitsCheck>("modernize-type-traits");
113 "modernize-unary-static-assert");
114 CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto");
115 CheckFactories.registerCheck<UseBoolLiteralsCheck>(
116 "modernize-use-bool-literals");
117 CheckFactories.registerCheck<UseConstraintsCheck>(
118 "modernize-use-constraints");
120 "modernize-use-default-member-init");
121 CheckFactories.registerCheck<UseEmplaceCheck>("modernize-use-emplace");
122 CheckFactories.registerCheck<UseEqualsDefaultCheck>(
123 "modernize-use-equals-default");
124 CheckFactories.registerCheck<UseEqualsDeleteCheck>(
125 "modernize-use-equals-delete");
126 CheckFactories.registerCheck<UseNodiscardCheck>("modernize-use-nodiscard");
127 CheckFactories.registerCheck<UseNoexceptCheck>("modernize-use-noexcept");
128 CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
129 CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
131 "modernize-use-trailing-return-type");
133 "modernize-use-transparent-functors");
135 "modernize-use-uncaught-exceptions");
136 CheckFactories.registerCheck<UseUsingCheck>("modernize-use-using");
137 }
138};
139
140// Register the ModernizeTidyModule using this statically initialized variable.
141static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module",
142 "Add modernize checks.");
143
144} // namespace modernize
145
146// This anchor is used to force the linker to link in the generated object file
147// and thus register the ModernizeModule.
148// NOLINTNEXTLINE(misc-use-internal-linkage)
150
151} // namespace clang::tidy
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.
Replace simple uses of std::bind with a lambda.
Find C-style array types and recommend to use std::array<> / std::vector<>.
Guards against use of setjmp/longjmp in C++ code.
Find all function definitions of C-style variadic functions.
This check replaces deprecated C library headers with their C++ STL alternatives.
This check warns the uses of the deprecated member types of std::ios_base and replaces those that hav...
Replaces groups of related macros with an unscoped anonymous enum.
Replaces nested std::min and std::max calls with an initializer list where applicable.
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
This check replaces string literals with escaped characters to raw string literals.
Find and remove redundant void argument lists.
Transforms the deprecated std::auto_ptr into the C++11 std::unique_ptr.
This check finds macro expansions of DISALLOW_COPY_AND_ASSIGN(Type) and replaces them with a deleted ...
std::random_shuffle will be removed as of C++17.
Use a braced init list for return statements rather than unnecessary repeating the return type name.
Replace copy and swap tricks on shrinkable containers with the shrink_to_fit() method call.
Converts standard library type traits of the form traits<...>::type and traits<......
Replaces a static_assert declaration with an empty message with the unary version.
Finds integer literals which are cast to bool.
Replace enable_if with C++20 requires clauses.
Convert a default constructor's member initializers into default member initializers.
Finds initializer lists for aggregate type that could be written as designated initializers instead.
This check looks for cases when inserting new element into std::vector but the element is constructed...
Replace default bodies of special member functions with '= default;'.
Identifies unimplemented private special member functions, and recommends using = delete for them.
Replace comparisons between signed and unsigned integers with their safe C++20 std::cmp_* alternative...
Add [[nodiscard]] to non-void const-member functions with no arguments or pass-by-value or pass by co...
Replace dynamic exception specifications, with noexcept (or user-defined macro) or noexcept(false).
Use C++11's override and remove virtual where applicable.
Detects calls to standard library iterator algorithms that could be replaced with a ranges version in...
Finds uses of std::lock_guard and suggests replacing them with C++17's / alternative std::scoped_lock...
Checks for common roundabout ways to express starts_with and / ends_with and suggests replacing with ...
Converts calls to absl::StrFormat, or other functions via configuration options, to C++20's std::form...
Finds constants and function calls to math functions that can be replaced with c++20's mathematical c...
Convert calls to printf-like functions to std::print and std::println.
Rewrites function signatures to use a trailing return type.
Prefer using transparent functors to non-transparent ones.
This check will warn on calls to std::uncaught_exception and replace them with calls to std::uncaught...
Check finds typedefs and replaces it with usings.
static ClangTidyModuleRegistry::Add< ModernizeModule > X("modernize-module", "Add modernize checks.")
volatile int ModernizeModuleAnchorSource