clang-tools  3.8.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 "LoopConvertCheck.h"
14 #include "MakeUniqueCheck.h"
15 #include "PassByValueCheck.h"
16 #include "RedundantVoidArgCheck.h"
17 #include "ReplaceAutoPtrCheck.h"
18 #include "ShrinkToFitCheck.h"
19 #include "UseAutoCheck.h"
20 #include "UseDefaultCheck.h"
21 #include "UseNullptrCheck.h"
22 #include "UseOverrideCheck.h"
23 
24 using namespace clang::ast_matchers;
25 
26 namespace clang {
27 namespace tidy {
28 namespace modernize {
29 
31 public:
32  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
33  CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert");
34  CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique");
35  CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value");
36  CheckFactories.registerCheck<RedundantVoidArgCheck>(
37  "modernize-redundant-void-arg");
38  CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
39  "modernize-replace-auto-ptr");
40  CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit");
41  CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto");
42  CheckFactories.registerCheck<UseDefaultCheck>("modernize-use-default");
43  CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
44  CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
45  }
46 
48  ClangTidyOptions Options;
49  auto &Opts = Options.CheckOptions;
50  // For types whose size in bytes is above this threshold, we prefer taking a
51  // const-reference than making a copy.
52  Opts["modernize-loop-convert.MaxCopySize"] = "16";
53 
54  Opts["modernize-loop-convert.MinConfidence"] = "reasonable";
55  Opts["modernize-loop-convert.NamingStyle"] = "CamelCase";
56  Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google".
57  Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google".
58 
59  // Comma-separated list of macros that behave like NULL.
60  Opts["modernize-use-nullptr.NullMacros"] = "NULL";
61  return Options;
62  }
63 };
64 
65 // Register the ModernizeTidyModule using this statically initialized variable.
66 static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module",
67  "Add modernize checks.");
68 
69 } // namespace modernize
70 
71 // This anchor is used to force the linker to link in the generated object file
72 // and thus register the ModernizeModule.
73 volatile int ModernizeModuleAnchorSource = 0;
74 
75 } // namespace tidy
76 } // namespace clang
static ClangTidyModuleRegistry::Add< ModernizeModule > X("modernize-module","Add modernize checks.")
Transforms the deprecated std::auto_ptr into the C++11 std::unique_ptr.
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.
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module...
volatile int ModernizeModuleAnchorSource
Replace copy and swap tricks on shrinkable containers with the shrink_to_fit() method call...