]> granicus.if.org Git - clang/commitdiff
Follow-up to r207071: Let newFrontendActionFactory() return a unique_ptr.
authorNico Weber <nicolasweber@gmx.de>
Mon, 28 Apr 2014 04:57:14 +0000 (04:57 +0000)
committerNico Weber <nicolasweber@gmx.de>
Mon, 28 Apr 2014 04:57:14 +0000 (04:57 +0000)
This exposed a leak, fix that.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207396 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Tooling/Tooling.h
tools/clang-check/ClangCheck.cpp

index ece38fc7e7425130828146a183bf8b35301eabd1..a0d6cb789cf446ca89b823ed544e0cfb09a30ce8 100644 (file)
@@ -97,7 +97,7 @@ public:
 /// FrontendActionFactory *Factory =
 ///   newFrontendActionFactory<clang::SyntaxOnlyAction>();
 template <typename T>
-FrontendActionFactory *newFrontendActionFactory();
+std::unique_ptr<FrontendActionFactory> newFrontendActionFactory();
 
 /// \brief Callbacks called before and after each source file processed by a
 /// FrontendAction created by the FrontedActionFactory returned by \c
@@ -126,10 +126,10 @@ public:
 /// struct ProvidesASTConsumers {
 ///   clang::ASTConsumer *newASTConsumer();
 /// } Factory;
-/// FrontendActionFactory *FactoryAdapter =
-///   newFrontendActionFactory(&Factory);
+/// std::unique_ptr<FrontendActionFactory> FactoryAdapter(
+///   newFrontendActionFactory(&Factory));
 template <typename FactoryT>
-inline FrontendActionFactory *newFrontendActionFactory(
+inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory(
     FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks = NULL);
 
 /// \brief Runs (and deletes) the tool on 'Code' with the -fsyntax-only flag.
@@ -305,17 +305,18 @@ class ClangTool {
 };
 
 template <typename T>
-FrontendActionFactory *newFrontendActionFactory() {
+std::unique_ptr<FrontendActionFactory> newFrontendActionFactory() {
   class SimpleFrontendActionFactory : public FrontendActionFactory {
   public:
     clang::FrontendAction *create() override { return new T; }
   };
 
-  return new SimpleFrontendActionFactory;
+  return std::unique_ptr<FrontendActionFactory>(
+      new SimpleFrontendActionFactory);
 }
 
 template <typename FactoryT>
-inline FrontendActionFactory *newFrontendActionFactory(
+inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory(
     FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks) {
   class FrontendActionFactoryAdapter : public FrontendActionFactory {
   public:
@@ -362,7 +363,8 @@ inline FrontendActionFactory *newFrontendActionFactory(
     SourceFileCallbacks *Callbacks;
   };
 
-  return new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks);
+  return std::unique_ptr<FrontendActionFactory>(
+      new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks));
 }
 
 /// \brief Returns the absolute path of \c File, by prepending it with
index 4fc970c0d121e461edf20165a20a65f5cb62468f..cc8d43cec221163de8f7f7f89af3516e2624c841 100644 (file)
@@ -215,7 +215,7 @@ int main(int argc, const char **argv) {
         Analyze ? "--analyze" : "-fsyntax-only", InsertAdjuster::BEGIN));
 
   clang_check::ClangCheckActionFactory CheckFactory;
-  FrontendActionFactory *FrontendFactory;
+  std::unique_ptr<FrontendActionFactory> FrontendFactory;
 
   // Choose the correct factory based on the selected mode.
   if (Analyze)
@@ -225,5 +225,5 @@ int main(int argc, const char **argv) {
   else
     FrontendFactory = newFrontendActionFactory(&CheckFactory);
 
-  return Tool.run(FrontendFactory);
+  return Tool.run(FrontendFactory.get());
 }