[clang-tools-extra] r372978 - Use std::unique_ptr in ClangTidyCheckFactories

Dmitri Gribenko via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 26 06:47:30 PDT 2019


Author: gribozavr
Date: Thu Sep 26 06:47:29 2019
New Revision: 372978

URL: http://llvm.org/viewvc/llvm-project?rev=372978&view=rev
Log:
Use std::unique_ptr in ClangTidyCheckFactories

I had to explicitly define some destructors that could only be defined
in the corresponding .cpp files.

Modified:
    clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
    clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp
    clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h
    clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
    clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h?rev=372978&r1=372977&r2=372978&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h Thu Sep 26 06:47:29 2019
@@ -13,6 +13,7 @@
 #include "llvm/ADT/StringRef.h"
 #include <functional>
 #include <map>
+#include <memory>
 #include <string>
 #include <utility>
 
@@ -25,9 +26,8 @@ namespace tidy {
 /// this object.
 class ClangTidyCheckFactories {
 public:
-  typedef std::function<ClangTidyCheck *(StringRef Name,
-                                         ClangTidyContext *Context)>
-      CheckFactory;
+  using CheckFactory = std::function<std::unique_ptr<ClangTidyCheck>(
+      StringRef Name, ClangTidyContext *Context)>;
 
   /// Registers check \p Factory with name \p Name.
   ///
@@ -58,7 +58,7 @@ public:
   template <typename CheckType> void registerCheck(StringRef CheckName) {
     registerCheckFactory(CheckName,
                          [](StringRef Name, ClangTidyContext *Context) {
-                           return new CheckType(Name, Context);
+                           return std::make_unique<CheckType>(Name, Context);
                          });
   }
 

Modified: clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp?rev=372978&r1=372977&r2=372978&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.cpp Thu Sep 26 06:47:29 2019
@@ -55,6 +55,8 @@ TodoCommentCheck::TodoCommentCheck(Strin
       Handler(std::make_unique<TodoCommentHandler>(
           *this, Context->getOptions().User)) {}
 
+TodoCommentCheck::~TodoCommentCheck() = default;
+
 void TodoCommentCheck::registerPPCallbacks(const SourceManager &SM,
                                            Preprocessor *PP,
                                            Preprocessor *ModuleExpanderPP) {

Modified: clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h?rev=372978&r1=372977&r2=372978&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/google/TodoCommentCheck.h Thu Sep 26 06:47:29 2019
@@ -22,6 +22,8 @@ namespace readability {
 class TodoCommentCheck : public ClangTidyCheck {
 public:
   TodoCommentCheck(StringRef Name, ClangTidyContext *Context);
+  ~TodoCommentCheck();
+
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
                            Preprocessor *ModuleExpanderPP) override;
 

Modified: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=372978&r1=372977&r2=372978&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp Thu Sep 26 06:47:29 2019
@@ -193,6 +193,8 @@ IdentifierNamingCheck::IdentifierNamingC
   IgnoreFailedSplit = Options.get("IgnoreFailedSplit", 0);
 }
 
+IdentifierNamingCheck::~IdentifierNamingCheck() = default;
+
 void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   auto const toString = [](CaseType Type) {
     switch (Type) {

Modified: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h?rev=372978&r1=372977&r2=372978&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.h Thu Sep 26 06:47:29 2019
@@ -34,6 +34,7 @@ namespace readability {
 class IdentifierNamingCheck : public ClangTidyCheck {
 public:
   IdentifierNamingCheck(StringRef Name, ClangTidyContext *Context);
+  ~IdentifierNamingCheck();
 
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;




More information about the cfe-commits mailing list