clang-tools  4.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"
22 #include "ShrinkToFitCheck.h"
23 #include "UseAutoCheck.h"
24 #include "UseBoolLiteralsCheck.h"
26 #include "UseEmplaceCheck.h"
27 #include "UseEqualsDefaultCheck.h"
28 #include "UseEqualsDeleteCheck.h"
29 #include "UseNullptrCheck.h"
30 #include "UseOverrideCheck.h"
32 #include "UseUsingCheck.h"
33 
34 using namespace clang::ast_matchers;
35 
36 namespace clang {
37 namespace tidy {
38 namespace modernize {
39 
41 public:
42  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
43  CheckFactories.registerCheck<AvoidBindCheck>("modernize-avoid-bind");
44  CheckFactories.registerCheck<DeprecatedHeadersCheck>(
45  "modernize-deprecated-headers");
46  CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert");
47  CheckFactories.registerCheck<MakeSharedCheck>("modernize-make-shared");
48  CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique");
49  CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value");
50  CheckFactories.registerCheck<RawStringLiteralCheck>(
51  "modernize-raw-string-literal");
52  CheckFactories.registerCheck<RedundantVoidArgCheck>(
53  "modernize-redundant-void-arg");
54  CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
55  "modernize-replace-auto-ptr");
56  CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit");
57  CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto");
58  CheckFactories.registerCheck<UseBoolLiteralsCheck>(
59  "modernize-use-bool-literals");
61  "modernize-use-default-member-init");
62  CheckFactories.registerCheck<UseEmplaceCheck>("modernize-use-emplace");
63  CheckFactories.registerCheck<UseEqualsDefaultCheck>("modernize-use-equals-default");
64  CheckFactories.registerCheck<UseEqualsDeleteCheck>(
65  "modernize-use-equals-delete");
66  CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
67  CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
69  "modernize-use-transparent-functors");
70  CheckFactories.registerCheck<UseUsingCheck>("modernize-use-using");
71  }
72 
74  ClangTidyOptions Options;
75  auto &Opts = Options.CheckOptions;
76  // For types whose size in bytes is above this threshold, we prefer taking a
77  // const-reference than making a copy.
78  Opts["modernize-loop-convert.MaxCopySize"] = "16";
79 
80  Opts["modernize-loop-convert.MinConfidence"] = "reasonable";
81  Opts["modernize-loop-convert.NamingStyle"] = "CamelCase";
82  Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google".
83  Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google".
84 
85  // Comma-separated list of macros that behave like NULL.
86  Opts["modernize-use-nullptr.NullMacros"] = "NULL";
87  return Options;
88  }
89 };
90 
91 // Register the ModernizeTidyModule using this statically initialized variable.
92 static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module",
93  "Add modernize checks.");
94 
95 } // namespace modernize
96 
97 // This anchor is used to force the linker to link in the generated object file
98 // and thus register the ModernizeModule.
99 volatile int ModernizeModuleAnchorSource = 0;
100 
101 } // namespace tidy
102 } // 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.
static clang::FrontendPluginRegistry::Add< clang::tidy::ClangTidyPluginAction > X("clang-tidy","clang-tidy")
Use C++11's override and remove virtual where applicable.
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Convert a default constructor's member initializers into default member initializers.
Contains options for clang-tidy.
Replace default bodies of special member functions with '= default;'.
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.
This check replaces deprecated C library headers with their C++ STL alternatives. ...
Prefer using transparent functors to non-transparent ones.
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 '= delete'.
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...