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