<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">The function passed to registerObserver() is used after the function returns, so we cannot make it a llvm::function_ref. This is a minus delta patch that apparently simplifies the stuff.</span></div>

<div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jul 27, 2014 at 12:21 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Why? inst't llvm::function_ref preferred when it is valid?<br>
<div class="HOEnZb"><div class="h5"><br>
On 17 July 2014 17:23, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
> Author: ruiu<br>
> Date: Thu Jul 17 16:23:52 2014<br>
> New Revision: 213312<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=213312&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=213312&view=rev</a><br>
> Log:<br>
> Use std::function instead of llvm::function_ref.<br>
><br>
> Modified:<br>
>     lld/trunk/include/lld/Core/InputGraph.h<br>
>     lld/trunk/lib/Core/InputGraph.cpp<br>
>     lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp<br>
><br>
> Modified: lld/trunk/include/lld/Core/InputGraph.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=213312&r1=213311&r2=213312&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/InputGraph.h?rev=213312&r1=213311&r2=213312&view=diff</a><br>


> ==============================================================================<br>
> --- lld/trunk/include/lld/Core/InputGraph.h (original)<br>
> +++ lld/trunk/include/lld/Core/InputGraph.h Thu Jul 17 16:23:52 2014<br>
> @@ -24,6 +24,7 @@<br>
>  #include "llvm/Support/MemoryBuffer.h"<br>
>  #include "llvm/Support/raw_ostream.h"<br>
><br>
> +#include <functional><br>
>  #include <memory><br>
>  #include <stack><br>
>  #include <vector><br>
> @@ -71,7 +72,7 @@ public:<br>
>    /// Adds an observer of getNextFile(). Each time a new file is about to be<br>
>    /// returned from getNextFile(), registered observers are called with the file<br>
>    /// being returned.<br>
> -  void registerObserver(llvm::function_ref<void(File *)> fn);<br>
> +  void registerObserver(std::function<void(File *)>);<br>
><br>
>    /// \brief Adds a node into the InputGraph<br>
>    void addInputElement(std::unique_ptr<InputElement>);<br>
> @@ -99,7 +100,7 @@ protected:<br>
>    // Index of the next element to be processed<br>
>    uint32_t _nextElementIndex;<br>
>    InputElement *_currentInputElement;<br>
> -  std::vector<llvm::function_ref<void(File *)>> _observers;<br>
> +  std::vector<std::function<void(File *)>> _observers;<br>
><br>
>  private:<br>
>    ErrorOr<InputElement *> getNextInputElement();<br>
><br>
> Modified: lld/trunk/lib/Core/InputGraph.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/InputGraph.cpp?rev=213312&r1=213311&r2=213312&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/InputGraph.cpp?rev=213312&r1=213311&r2=213312&view=diff</a><br>


> ==============================================================================<br>
> --- lld/trunk/lib/Core/InputGraph.cpp (original)<br>
> +++ lld/trunk/lib/Core/InputGraph.cpp Thu Jul 17 16:23:52 2014<br>
> @@ -38,7 +38,7 @@ ErrorOr<File &> InputGraph::getNextFile(<br>
><br>
>  void InputGraph::notifyProgress() { _currentInputElement->notifyProgress(); }<br>
><br>
> -void InputGraph::registerObserver(llvm::function_ref<void(File *)> fn) {<br>
> +void InputGraph::registerObserver(std::function<void(File *)> fn) {<br>
>    _observers.push_back(fn);<br>
>  }<br>
><br>
><br>
> Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=213312&r1=213311&r2=213312&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp?rev=213312&r1=213311&r2=213312&view=diff</a><br>


> ==============================================================================<br>
> --- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp (original)<br>
> +++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp Thu Jul 17 16:23:52 2014<br>
> @@ -101,20 +101,6 @@ std::unique_ptr<File> PECOFFLinkingConte<br>
>        "<command line option /include>");<br>
>  }<br>
><br>
> -namespace {<br>
> -// As per policy, we cannot use std::function.<br>
> -class ObserverCallback {<br>
> -public:<br>
> -  explicit ObserverCallback(pecoff::ExportedSymbolRenameFile *f)<br>
> -      : _renameFile(f) {}<br>
> -<br>
> -  void operator()(File *file) { _renameFile->addResolvableSymbols(file); }<br>
> -<br>
> -private:<br>
> -  pecoff::ExportedSymbolRenameFile *_renameFile;<br>
> -};<br>
> -} // end anonymous namespace<br>
> -<br>
>  bool PECOFFLinkingContext::createImplicitFiles(<br>
>      std::vector<std::unique_ptr<File>> &) const {<br>
>    // Create a file for __ImageBase.<br>
> @@ -140,7 +126,7 @@ bool PECOFFLinkingContext::createImplici<br>
>    exportNode->appendInputFile(std::unique_ptr<File>(renameFile));<br>
>    getLibraryGroup()->addFile(std::move(exportNode));<br>
>    getInputGraph().registerObserver(<br>
> -      *(new (_allocator) ObserverCallback(renameFile)));<br>
> +      [=](File *file) { renameFile->addResolvableSymbols(file); });<br>
>    return true;<br>
>  }<br>
><br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>