clang-tools  14.0.0git
ModernizeTidyModule.cpp
Go to the documentation of this file.
1 //===--- ModernizeTidyModule.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 "AvoidBindCheck.h"
13 #include "AvoidCArraysCheck.h"
15 #include "DeprecatedHeadersCheck.h"
17 #include "LoopConvertCheck.h"
18 #include "MakeSharedCheck.h"
19 #include "MakeUniqueCheck.h"
20 #include "PassByValueCheck.h"
21 #include "RawStringLiteralCheck.h"
22 #include "RedundantVoidArgCheck.h"
23 #include "ReplaceAutoPtrCheck.h"
27 #include "ShrinkToFitCheck.h"
28 #include "UnaryStaticAssertCheck.h"
29 #include "UseAutoCheck.h"
30 #include "UseBoolLiteralsCheck.h"
32 #include "UseEmplaceCheck.h"
33 #include "UseEqualsDefaultCheck.h"
34 #include "UseEqualsDeleteCheck.h"
35 #include "UseNodiscardCheck.h"
36 #include "UseNoexceptCheck.h"
37 #include "UseNullptrCheck.h"
38 #include "UseOverrideCheck.h"
42 #include "UseUsingCheck.h"
43 
44 using namespace clang::ast_matchers;
45 
46 namespace clang {
47 namespace tidy {
48 namespace modernize {
49 
51 public:
52  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
53  CheckFactories.registerCheck<AvoidBindCheck>("modernize-avoid-bind");
54  CheckFactories.registerCheck<AvoidCArraysCheck>("modernize-avoid-c-arrays");
56  "modernize-concat-nested-namespaces");
57  CheckFactories.registerCheck<DeprecatedHeadersCheck>(
58  "modernize-deprecated-headers");
60  "modernize-deprecated-ios-base-aliases");
61  CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert");
62  CheckFactories.registerCheck<MakeSharedCheck>("modernize-make-shared");
63  CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique");
64  CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value");
65  CheckFactories.registerCheck<RawStringLiteralCheck>(
66  "modernize-raw-string-literal");
67  CheckFactories.registerCheck<RedundantVoidArgCheck>(
68  "modernize-redundant-void-arg");
69  CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
70  "modernize-replace-auto-ptr");
72  "modernize-replace-disallow-copy-and-assign-macro");
74  "modernize-replace-random-shuffle");
76  "modernize-return-braced-init-list");
77  CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit");
78  CheckFactories.registerCheck<UnaryStaticAssertCheck>(
79  "modernize-unary-static-assert");
80  CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto");
81  CheckFactories.registerCheck<UseBoolLiteralsCheck>(
82  "modernize-use-bool-literals");
84  "modernize-use-default-member-init");
85  CheckFactories.registerCheck<UseEmplaceCheck>("modernize-use-emplace");
86  CheckFactories.registerCheck<UseEqualsDefaultCheck>("modernize-use-equals-default");
87  CheckFactories.registerCheck<UseEqualsDeleteCheck>(
88  "modernize-use-equals-delete");
89  CheckFactories.registerCheck<UseNodiscardCheck>(
90  "modernize-use-nodiscard");
91  CheckFactories.registerCheck<UseNoexceptCheck>("modernize-use-noexcept");
92  CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
93  CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
95  "modernize-use-trailing-return-type");
97  "modernize-use-transparent-functors");
99  "modernize-use-uncaught-exceptions");
100  CheckFactories.registerCheck<UseUsingCheck>("modernize-use-using");
101  }
102 
104  ClangTidyOptions Options;
105  auto &Opts = Options.CheckOptions;
106  // For types whose size in bytes is above this threshold, we prefer taking a
107  // const-reference than making a copy.
108  Opts["modernize-loop-convert.MaxCopySize"] = "16";
109 
110  Opts["modernize-loop-convert.MinConfidence"] = "reasonable";
111  Opts["modernize-loop-convert.NamingStyle"] = "CamelCase";
112  Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google".
113  Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google".
114 
115  // Comma-separated list of macros that behave like NULL.
116  Opts["modernize-use-nullptr.NullMacros"] = "NULL";
117  return Options;
118  }
119 };
120 
121 // Register the ModernizeTidyModule using this statically initialized variable.
122 static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module",
123  "Add modernize checks.");
124 
125 } // namespace modernize
126 
127 // This anchor is used to force the linker to link in the generated object file
128 // and thus register the ModernizeModule.
130 
131 } // namespace tidy
132 } // namespace clang
UseUncaughtExceptionsCheck.h
UseTransparentFunctorsCheck.h
UseNoexceptCheck.h
clang::tidy::modernize::UseBoolLiteralsCheck
Finds integer literals which are cast to bool.
Definition: UseBoolLiteralsCheck.h:22
UseNullptrCheck.h
clang::tidy::modernize::UseAutoCheck
Definition: UseAutoCheck.h:18
clang::tidy::modernize::UseEmplaceCheck
This check looks for cases when inserting new element into std::vector but the element is constructed...
Definition: UseEmplaceCheck.h:27
clang::tidy::modernize::UseTrailingReturnTypeCheck
Rewrites function signatures to use a trailing return type.
Definition: UseTrailingReturnTypeCheck.h:29
clang::tidy::modernize::UseUsingCheck
Check finds typedefs and replaces it with usings.
Definition: UseUsingCheck.h:22
clang::tidy::modernize::UseDefaultMemberInitCheck
Convert a default constructor's member initializers into default member initializers.
Definition: UseDefaultMemberInitCheck.h:24
UseEqualsDeleteCheck.h
clang::tidy::modernize::RawStringLiteralCheck
This check replaces string literals with escaped characters to raw string literals.
Definition: RawStringLiteralCheck.h:26
clang::tidy::modernize::UseEqualsDefaultCheck
Replace default bodies of special member functions with '= default;'.
Definition: UseEqualsDefaultCheck.h:37
ReplaceDisallowCopyAndAssignMacroCheck.h
clang::tidy::modernize::ModernizeModule
Definition: ModernizeTidyModule.cpp:50
AvoidCArraysCheck.h
UseAutoCheck.h
clang::tidy::ClangTidyOptions::CheckOptions
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Definition: ClangTidyOptions.h:118
clang::tidy::modernize::LoopConvertCheck
Definition: LoopConvertCheck.h:20
LoopConvertCheck.h
UseEmplaceCheck.h
clang::tidy::modernize::PassByValueCheck
Definition: PassByValueCheck.h:21
clang::tidy::modernize::MakeUniqueCheck
Replace the pattern:
Definition: MakeUniqueCheck.h:27
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:50
UseEqualsDefaultCheck.h
RedundantVoidArgCheck.h
clang::ast_matchers
Definition: AbseilMatcher.h:14
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:28
AvoidBindCheck.h
RawStringLiteralCheck.h
UseTrailingReturnTypeCheck.h
clang::tidy::modernize::UseTransparentFunctorsCheck
Prefer using transparent functors to non-transparent ones.
Definition: UseTransparentFunctorsCheck.h:22
X
int X
Definition: LSPBinderTests.cpp:25
clang::tidy::modernize::MakeSharedCheck
Replace the pattern:
Definition: MakeSharedCheck.h:30
ShrinkToFitCheck.h
clang::tidy::modernize::RedundantVoidArgCheck
Find and remove redundant void argument lists.
Definition: RedundantVoidArgCheck.h:31
UseBoolLiteralsCheck.h
clang::tidy::modernize::ModernizeModule::getModuleOptions
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Definition: ModernizeTidyModule.cpp:103
clang::tidy::modernize::ConcatNestedNamespacesCheck
Definition: ConcatNestedNamespacesCheck.h:20
clang::tidy::modernize::DeprecatedHeadersCheck
This check replaces deprecated C library headers with their C++ STL alternatives.
Definition: DeprecatedHeadersCheck.h:35
UseNodiscardCheck.h
clang::tidy::modernize::UseOverrideCheck
Use C++11's override and remove virtual where applicable.
Definition: UseOverrideCheck.h:19
ReplaceAutoPtrCheck.h
clang::tidy::modernize::ReplaceAutoPtrCheck
Transforms the deprecated std::auto_ptr into the C++11 std::unique_ptr.
Definition: ReplaceAutoPtrCheck.h:43
ConcatNestedNamespacesCheck.h
MakeSharedCheck.h
clang::tidy::modernize::ReplaceDisallowCopyAndAssignMacroCheck
This check finds macro expansions of DISALLOW_COPY_AND_ASSIGN(Type) and replaces them with a deleted ...
Definition: ReplaceDisallowCopyAndAssignMacroCheck.h:41
clang::tidy::modernize::UseNodiscardCheck
Add [[nodiscard]] to non-void const-member functions with no arguments or pass-by-value or pass by co...
Definition: UseNodiscardCheck.h:34
DeprecatedHeadersCheck.h
UseDefaultMemberInitCheck.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::modernize::UseNoexceptCheck
Replace dynamic exception specifications, with noexcept (or user-defined macro) or noexcept(false).
Definition: UseNoexceptCheck.h:32
clang::tidy::modernize::ShrinkToFitCheck
Replace copy and swap tricks on shrinkable containers with the shrink_to_fit() method call.
Definition: ShrinkToFitCheck.h:24
clang::tidy::modernize::UseEqualsDeleteCheck
Mark unimplemented private special member functions with '= delete'.
Definition: UseEqualsDeleteCheck.h:37
clang::tidy::modernize::DeprecatedIosBaseAliasesCheck
This check warns the uses of the deprecated member types of std::ios_base and replaces those that hav...
Definition: DeprecatedIosBaseAliasesCheck.h:23
UseUsingCheck.h
clang::tidy::modernize::ReturnBracedInitListCheck
Use a braced init list for return statements rather than unnecessary repeating the return type name.
Definition: ReturnBracedInitListCheck.h:23
clang::tidy::modernize::ModernizeModule::addCheckFactories
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
Definition: ModernizeTidyModule.cpp:52
DeprecatedIosBaseAliasesCheck.h
UseOverrideCheck.h
PassByValueCheck.h
clang::tidy::ModernizeModuleAnchorSource
volatile int ModernizeModuleAnchorSource
Definition: ModernizeTidyModule.cpp:129
clang::tidy::modernize::UseNullptrCheck
Definition: UseNullptrCheck.h:18
clang::tidy::modernize::UseUncaughtExceptionsCheck
This check will warn on calls to std::uncaught_exception and replace them with calls to std::uncaught...
Definition: UseUncaughtExceptionsCheck.h:24
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:81
MakeUniqueCheck.h
clang::tidy::modernize::ReplaceRandomShuffleCheck
std::random_shuffle will be removed as of C++17.
Definition: ReplaceRandomShuffleCheck.h:24
ReplaceRandomShuffleCheck.h
clang::tidy::modernize::UnaryStaticAssertCheck
Replaces a static_assert declaration with an empty message with the unary version.
Definition: UnaryStaticAssertCheck.h:23
ReturnBracedInitListCheck.h
UnaryStaticAssertCheck.h
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:59
clang::tidy::modernize::AvoidCArraysCheck
Find C-style array types and recommend to use std::array<> / std::vector<>.
Definition: AvoidCArraysCheck.h:22
clang::tidy::modernize::AvoidBindCheck
Replace simple uses of std::bind with a lambda.
Definition: AvoidBindCheck.h:24