clang-tools  6.0.0
ModernizeTidyModule.cpp
Go to the documentation of this file.
1 //===--- ModernizeTidyModule.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 "AvoidBindCheck.h"
14 #include "DeprecatedHeadersCheck.h"
15 #include "LoopConvertCheck.h"
16 #include "MakeSharedCheck.h"
17 #include "MakeUniqueCheck.h"
18 #include "PassByValueCheck.h"
19 #include "RawStringLiteralCheck.h"
20 #include "RedundantVoidArgCheck.h"
21 #include "ReplaceAutoPtrCheck.h"
24 #include "ShrinkToFitCheck.h"
25 #include "UnaryStaticAssertCheck.h"
26 #include "UseAutoCheck.h"
27 #include "UseBoolLiteralsCheck.h"
29 #include "UseEmplaceCheck.h"
30 #include "UseEqualsDefaultCheck.h"
31 #include "UseEqualsDeleteCheck.h"
32 #include "UseNoexceptCheck.h"
33 #include "UseNullptrCheck.h"
34 #include "UseOverrideCheck.h"
36 #include "UseUsingCheck.h"
37 
38 using namespace clang::ast_matchers;
39 
40 namespace clang {
41 namespace tidy {
42 namespace modernize {
43 
45 public:
46  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
47  CheckFactories.registerCheck<AvoidBindCheck>("modernize-avoid-bind");
48  CheckFactories.registerCheck<DeprecatedHeadersCheck>(
49  "modernize-deprecated-headers");
50  CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert");
51  CheckFactories.registerCheck<MakeSharedCheck>("modernize-make-shared");
52  CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique");
53  CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value");
54  CheckFactories.registerCheck<RawStringLiteralCheck>(
55  "modernize-raw-string-literal");
56  CheckFactories.registerCheck<RedundantVoidArgCheck>(
57  "modernize-redundant-void-arg");
58  CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
59  "modernize-replace-auto-ptr");
61  "modernize-replace-random-shuffle");
63  "modernize-return-braced-init-list");
64  CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit");
65  CheckFactories.registerCheck<UnaryStaticAssertCheck>(
66  "modernize-unary-static-assert");
67  CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto");
68  CheckFactories.registerCheck<UseBoolLiteralsCheck>(
69  "modernize-use-bool-literals");
71  "modernize-use-default-member-init");
72  CheckFactories.registerCheck<UseEmplaceCheck>("modernize-use-emplace");
73  CheckFactories.registerCheck<UseEqualsDefaultCheck>("modernize-use-equals-default");
74  CheckFactories.registerCheck<UseEqualsDeleteCheck>(
75  "modernize-use-equals-delete");
76  CheckFactories.registerCheck<UseNoexceptCheck>("modernize-use-noexcept");
77  CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
78  CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
80  "modernize-use-transparent-functors");
81  CheckFactories.registerCheck<UseUsingCheck>("modernize-use-using");
82  }
83 
85  ClangTidyOptions Options;
86  auto &Opts = Options.CheckOptions;
87  // For types whose size in bytes is above this threshold, we prefer taking a
88  // const-reference than making a copy.
89  Opts["modernize-loop-convert.MaxCopySize"] = "16";
90 
91  Opts["modernize-loop-convert.MinConfidence"] = "reasonable";
92  Opts["modernize-loop-convert.NamingStyle"] = "CamelCase";
93  Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google".
94  Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google".
95 
96  // Comma-separated list of macros that behave like NULL.
97  Opts["modernize-use-nullptr.NullMacros"] = "NULL";
98  return Options;
99  }
100 };
101 
102 // Register the ModernizeTidyModule using this statically initialized variable.
103 static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module",
104  "Add modernize checks.");
105 
106 } // namespace modernize
107 
108 // This anchor is used to force the linker to link in the generated object file
109 // and thus register the ModernizeModule.
111 
112 } // namespace tidy
113 } // 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.
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.
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.
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.
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. ...
static clang::FrontendPluginRegistry::Add< clang::tidy::ClangTidyPluginAction > X("clang-tidy", "clang-tidy")
Prefer using transparent functors to non-transparent ones.
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:23
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...
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...