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 <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);
});
}

View File

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

View File

@ -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;

View File

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

View File

@ -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;