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