<div dir="ltr"><p dir="ltr"><br>
On Apr 27, 2014 10:06 PM, "Nico Weber" <<a href="mailto:nicolasweber@gmx.de" target="_blank">nicolasweber@gmx.de</a>> wrote:<br>
><br>
> Author: nico<br>
> Date: Sun Apr 27 23:57:14 2014<br>
> New Revision: 207396<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=207396&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=207396&view=rev</a><br>
> Log:<br>
> Follow-up to r207071: Let newFrontendActionFactory() return a unique_ptr.<br>
><br>
> This exposed a leak, fix that.<br>
><br>
> Modified:<br>
>     cfe/trunk/include/clang/Tooling/Tooling.h<br>
>     cfe/trunk/tools/clang-check/ClangCheck.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/Tooling/Tooling.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=207396&r1=207395&r2=207396&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=207396&r1=207395&r2=207396&view=diff</a><br>


> ==============================================================================<br>
> --- cfe/trunk/include/clang/Tooling/Tooling.h (original)<br>
> +++ cfe/trunk/include/clang/Tooling/Tooling.h Sun Apr 27 23:57:14 2014<br>
> @@ -97,7 +97,7 @@ public:<br>
>  /// FrontendActionFactory *Factory =<br>
>  ///   newFrontendActionFactory<clang::SyntaxOnlyAction>();<br>
>  template <typename T><br>
> -FrontendActionFactory *newFrontendActionFactory();<br>
> +std::unique_ptr<FrontendActionFactory> newFrontendActionFactory();<br>
><br>
>  /// \brief Callbacks called before and after each source file processed by a<br>
>  /// FrontendAction created by the FrontedActionFactory returned by \c<br>
> @@ -126,10 +126,10 @@ public:<br>
>  /// struct ProvidesASTConsumers {<br>
>  ///   clang::ASTConsumer *newASTConsumer();<br>
>  /// } Factory;<br>
> -/// FrontendActionFactory *FactoryAdapter =<br>
> -///   newFrontendActionFactory(&Factory);<br>
> +/// std::unique_ptr<FrontendActionFactory> FactoryAdapter(<br>
> +///   newFrontendActionFactory(&Factory));<br>
>  template <typename FactoryT><br>
> -inline FrontendActionFactory *newFrontendActionFactory(<br>
> +inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory(<br>
>      FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks = NULL);<br>
><br>
>  /// \brief Runs (and deletes) the tool on 'Code' with the -fsyntax-only flag.<br>
> @@ -305,17 +305,18 @@ class ClangTool {<br>
>  };<br>
><br>
>  template <typename T><br>
> -FrontendActionFactory *newFrontendActionFactory() {<br>
> +std::unique_ptr<FrontendActionFactory> newFrontendActionFactory() {<br>
>    class SimpleFrontendActionFactory : public FrontendActionFactory {<br>
>    public:<br>
>      clang::FrontendAction *create() override { return new T; }<br>
>    };<br>
><br>
> -  return new SimpleFrontendActionFactory;<br>
> +  return std::unique_ptr<FrontendActionFactory>(<br>
> +      new SimpleFrontendActionFactory);<br>
>  }<br>
><br>
>  template <typename FactoryT><br>
> -inline FrontendActionFactory *newFrontendActionFactory(<br>
> +inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory(<br>
>      FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks) {<br>
>    class FrontendActionFactoryAdapter : public FrontendActionFactory {<br>
>    public:<br>
> @@ -362,7 +363,8 @@ inline FrontendActionFactory *newFronten<br>
>      SourceFileCallbacks *Callbacks;<br>
>    };<br>
><br>
> -  return new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks);<br>
> +  return std::unique_ptr<FrontendActionFactory>(<br>
> +      new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks));</p><p>Could you use make_unique here? (one reason it's not possible to use that is when the ctor is private/friended, etc)</p><p dir="ltr">
>  }<br>
><br>
>  /// \brief Returns the absolute path of \c File, by prepending it with<br>
><br>
> Modified: cfe/trunk/tools/clang-check/ClangCheck.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-check/ClangCheck.cpp?rev=207396&r1=207395&r2=207396&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-check/ClangCheck.cpp?rev=207396&r1=207395&r2=207396&view=diff</a><br>


> ==============================================================================<br>
> --- cfe/trunk/tools/clang-check/ClangCheck.cpp (original)<br>
> +++ cfe/trunk/tools/clang-check/ClangCheck.cpp Sun Apr 27 23:57:14 2014<br>
> @@ -215,7 +215,7 @@ int main(int argc, const char **argv) {<br>
>          Analyze ? "--analyze" : "-fsyntax-only", InsertAdjuster::BEGIN));<br>
><br>
>    clang_check::ClangCheckActionFactory CheckFactory;<br>
> -  FrontendActionFactory *FrontendFactory;<br>
> +  std::unique_ptr<FrontendActionFactory> FrontendFactory;<br>
><br>
>    // Choose the correct factory based on the selected mode.<br>
>    if (Analyze)<br>
> @@ -225,5 +225,5 @@ int main(int argc, const char **argv) {<br>
>    else<br>
>      FrontendFactory = newFrontendActionFactory(&CheckFactory);<br>
><br>
> -  return Tool.run(FrontendFactory);<br>
> +  return Tool.run(FrontendFactory.get());<br>
>  }<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</p>
</div>