Use std::unique_ptr in ClangTidyCheckFactories

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

llvm-svn: 372978
This commit is contained in:
Dmitri Gribenko 2019-09-26 13:47:29 +00:00
parent c15cd009ac
commit 5338ffcfa1
5 changed files with 11 additions and 4 deletions

View File

@ -13,6 +13,7 @@
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include <functional> #include <functional>
#include <map> #include <map>
#include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
@ -25,9 +26,8 @@ namespace tidy {
/// this object. /// this object.
class ClangTidyCheckFactories { class ClangTidyCheckFactories {
public: public:
typedef std::function<ClangTidyCheck *(StringRef Name, using CheckFactory = std::function<std::unique_ptr<ClangTidyCheck>(
ClangTidyContext *Context)> StringRef Name, ClangTidyContext *Context)>;
CheckFactory;
/// Registers check \p Factory with name \p Name. /// Registers check \p Factory with name \p Name.
/// ///
@ -58,7 +58,7 @@ public:
template <typename CheckType> void registerCheck(StringRef CheckName) { template <typename CheckType> void registerCheck(StringRef CheckName) {
registerCheckFactory(CheckName, registerCheckFactory(CheckName,
[](StringRef Name, ClangTidyContext *Context) { [](StringRef Name, ClangTidyContext *Context) {
return new CheckType(Name, Context); return std::make_unique<CheckType>(Name, Context);
}); });
} }

View File

@ -55,6 +55,8 @@ TodoCommentCheck::TodoCommentCheck(StringRef Name, ClangTidyContext *Context)
Handler(std::make_unique<TodoCommentHandler>( Handler(std::make_unique<TodoCommentHandler>(
*this, Context->getOptions().User)) {} *this, Context->getOptions().User)) {}
TodoCommentCheck::~TodoCommentCheck() = default;
void TodoCommentCheck::registerPPCallbacks(const SourceManager &SM, void TodoCommentCheck::registerPPCallbacks(const SourceManager &SM,
Preprocessor *PP, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) { Preprocessor *ModuleExpanderPP) {

View File

@ -22,6 +22,8 @@ namespace readability {
class TodoCommentCheck : public ClangTidyCheck { class TodoCommentCheck : public ClangTidyCheck {
public: public:
TodoCommentCheck(StringRef Name, ClangTidyContext *Context); TodoCommentCheck(StringRef Name, ClangTidyContext *Context);
~TodoCommentCheck();
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override; Preprocessor *ModuleExpanderPP) override;

View File

@ -193,6 +193,8 @@ IdentifierNamingCheck::IdentifierNamingCheck(StringRef Name,
IgnoreFailedSplit = Options.get("IgnoreFailedSplit", 0); IgnoreFailedSplit = Options.get("IgnoreFailedSplit", 0);
} }
IdentifierNamingCheck::~IdentifierNamingCheck() = default;
void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { void IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
auto const toString = [](CaseType Type) { auto const toString = [](CaseType Type) {
switch (Type) { switch (Type) {

View File

@ -34,6 +34,7 @@ namespace readability {
class IdentifierNamingCheck : public ClangTidyCheck { class IdentifierNamingCheck : public ClangTidyCheck {
public: public:
IdentifierNamingCheck(StringRef Name, ClangTidyContext *Context); IdentifierNamingCheck(StringRef Name, ClangTidyContext *Context);
~IdentifierNamingCheck();
void storeOptions(ClangTidyOptions::OptionMap &Opts) override; void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override; void registerMatchers(ast_matchers::MatchFinder *Finder) override;