clang-tools  3.9.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"
25 #include "UseDefaultCheck.h"
26 #include "UseEmplaceCheck.h"
27 #include "UseNullptrCheck.h"
28 #include "UseOverrideCheck.h"
29 #include "UseUsingCheck.h"
30 
31 using namespace clang::ast_matchers;
32 
33 namespace clang {
34 namespace tidy {
35 namespace modernize {
36 
38 public:
39  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
40  CheckFactories.registerCheck<AvoidBindCheck>(
41  "modernize-avoid-bind");
42  CheckFactories.registerCheck<DeprecatedHeadersCheck>(
43  "modernize-deprecated-headers");
44  CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert");
45  CheckFactories.registerCheck<MakeSharedCheck>("modernize-make-shared");
46  CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique");
47  CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value");
48  CheckFactories.registerCheck<RawStringLiteralCheck>(
49  "modernize-raw-string-literal");
50  CheckFactories.registerCheck<RedundantVoidArgCheck>(
51  "modernize-redundant-void-arg");
52  CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
53  "modernize-replace-auto-ptr");
54  CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit");
55  CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto");
56  CheckFactories.registerCheck<UseBoolLiteralsCheck>(
57  "modernize-use-bool-literals");
58  CheckFactories.registerCheck<UseDefaultCheck>("modernize-use-default");
59  CheckFactories.registerCheck<UseEmplaceCheck>("modernize-use-emplace");
60  CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
61  CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
62  CheckFactories.registerCheck<UseUsingCheck>("modernize-use-using");
63  }
64 
66  ClangTidyOptions Options;
67  auto &Opts = Options.CheckOptions;
68  // For types whose size in bytes is above this threshold, we prefer taking a
69  // const-reference than making a copy.
70  Opts["modernize-loop-convert.MaxCopySize"] = "16";
71 
72  Opts["modernize-loop-convert.MinConfidence"] = "reasonable";
73  Opts["modernize-loop-convert.NamingStyle"] = "CamelCase";
74  Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google".
75  Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google".
76 
77  // Comma-separated list of macros that behave like NULL.
78  Opts["modernize-use-nullptr.NullMacros"] = "NULL";
79  return Options;
80  }
81 };
82 
83 // Register the ModernizeTidyModule using this statically initialized variable.
84 static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module",
85  "Add modernize checks.");
86 
87 } // namespace modernize
88 
89 // This anchor is used to force the linker to link in the generated object file
90 // and thus register the ModernizeModule.
91 volatile int ModernizeModuleAnchorSource = 0;
92 
93 } // namespace tidy
94 } // 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.
Contains options for clang-tidy.
A collection of ClangTidyCheckFactory instances.
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Replace default bodies of special member functions with '= default;'.
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. ...
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
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...