[clang-tidy] Don't leak the TodoCommentHandler object

Preprocessor:addCommentHandler() does not take ownership,
so we'd end up leaking the TodoCommentHandler.

This patch makes it owned by the Check object.

Differential Revision: http://reviews.llvm.org/D5402

llvm-svn: 218068
This commit is contained in:
Hans Wennborg 2014-09-18 18:59:50 +00:00
parent 9767d2f8da
commit dfd8c74a98
2 changed files with 14 additions and 6 deletions

View File

@ -15,8 +15,7 @@ namespace clang {
namespace tidy { namespace tidy {
namespace readability { namespace readability {
namespace { class TodoCommentCheck::TodoCommentHandler : public CommentHandler {
class TodoCommentHandler : public CommentHandler {
public: public:
explicit TodoCommentHandler(TodoCommentCheck &Check) explicit TodoCommentHandler(TodoCommentCheck &Check)
: Check(Check), TodoMatch("^// *TODO(\\(.*\\))?:?( )?(.*)$") {} : Check(Check), TodoMatch("^// *TODO(\\(.*\\))?:?( )?(.*)$") {}
@ -54,10 +53,15 @@ private:
TodoCommentCheck &Check; TodoCommentCheck &Check;
llvm::Regex TodoMatch; llvm::Regex TodoMatch;
}; };
} // namespace
TodoCommentCheck::TodoCommentCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
Handler(llvm::make_unique<TodoCommentHandler>(*this)) {}
TodoCommentCheck::~TodoCommentCheck() {}
void TodoCommentCheck::registerPPCallbacks(CompilerInstance &Compiler) { void TodoCommentCheck::registerPPCallbacks(CompilerInstance &Compiler) {
Compiler.getPreprocessor().addCommentHandler(new TodoCommentHandler(*this)); Compiler.getPreprocessor().addCommentHandler(Handler.get());
} }
} // namespace readability } // namespace readability

View File

@ -21,9 +21,13 @@ namespace readability {
/// Corresponding cpplint.py check: readability/todo /// Corresponding cpplint.py check: readability/todo
class TodoCommentCheck : public ClangTidyCheck { class TodoCommentCheck : public ClangTidyCheck {
public: public:
TodoCommentCheck(StringRef Name, ClangTidyContext *Context) TodoCommentCheck(StringRef Name, ClangTidyContext *Context);
: ClangTidyCheck(Name, Context) {} ~TodoCommentCheck();
void registerPPCallbacks(CompilerInstance &Compiler) override; void registerPPCallbacks(CompilerInstance &Compiler) override;
private:
class TodoCommentHandler;
std::unique_ptr<TodoCommentHandler> Handler;
}; };
} // namespace readability } // namespace readability