forked from OSchip/llvm-project
[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:
parent
9767d2f8da
commit
dfd8c74a98
|
@ -15,8 +15,7 @@ namespace clang {
|
|||
namespace tidy {
|
||||
namespace readability {
|
||||
|
||||
namespace {
|
||||
class TodoCommentHandler : public CommentHandler {
|
||||
class TodoCommentCheck::TodoCommentHandler : public CommentHandler {
|
||||
public:
|
||||
explicit TodoCommentHandler(TodoCommentCheck &Check)
|
||||
: Check(Check), TodoMatch("^// *TODO(\\(.*\\))?:?( )?(.*)$") {}
|
||||
|
@ -54,10 +53,15 @@ private:
|
|||
TodoCommentCheck &Check;
|
||||
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) {
|
||||
Compiler.getPreprocessor().addCommentHandler(new TodoCommentHandler(*this));
|
||||
Compiler.getPreprocessor().addCommentHandler(Handler.get());
|
||||
}
|
||||
|
||||
} // namespace readability
|
||||
|
|
|
@ -21,9 +21,13 @@ namespace readability {
|
|||
/// Corresponding cpplint.py check: readability/todo
|
||||
class TodoCommentCheck : public ClangTidyCheck {
|
||||
public:
|
||||
TodoCommentCheck(StringRef Name, ClangTidyContext *Context)
|
||||
: ClangTidyCheck(Name, Context) {}
|
||||
TodoCommentCheck(StringRef Name, ClangTidyContext *Context);
|
||||
~TodoCommentCheck();
|
||||
void registerPPCallbacks(CompilerInstance &Compiler) override;
|
||||
|
||||
private:
|
||||
class TodoCommentHandler;
|
||||
std::unique_ptr<TodoCommentHandler> Handler;
|
||||
};
|
||||
|
||||
} // namespace readability
|
||||
|
|
Loading…
Reference in New Issue