title: Why "Potential leak of memory pointed to by field" on Factory look-up-table
body: <p>I'm trying to implement a factory which creates new instances of types inherited by a common base class <em>Field</em>.</p>
  
  <p>The factory is modeled as look-up-table to factory functions which return a unique_ptr. The key type of the look-up-table is a string_view.</p>
  
  <p>Within the factory functions I call make_unique for the requested type.</p>
  
  <p>clang-analyzer complains about a potential memory leak at the return of the unique_ptr.</p>
  
  <p>The factory look-up-table with a single available factory entry.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>  using FieldFactory = std::function&lt; std::unique_ptr&lt; Field &gt;( node const&amp;, Clf const&amp; ) &gt;;
  
    static const std::unordered_map&lt; std::string_view, FieldFactory &gt; fieldFactoryLut = {
      {"static-text"sv, []( auto const&amp; node, auto const&amp; parent ) { return std::make_unique&lt; StaticTextField &gt;( node, parent ); }}
    };
  
  </code></pre>
  
  <p>Usage</p>
  
  <pre class="lang-cpp prettyprint-override"><code>auto const&amp; factoryFun = fieldFactoryLut.at("static-text"sv);
  auto uPtr = factoryFun(node, clf);
  
  </code></pre>
  
  <p>By calling make_unique I expect no possible memory leak, but clang-analyzer claims:</p>
  
  <pre><code>warning: Potential leak of memory pointed to by field '_M_head_impl' [clang-analyzer-cplusplus.NewDeleteLeaks]
  [build]     {"static-text"sv, []( auto const&amp; node, auto const&amp; parent ) { return std::make_unique&lt; StaticTextField &gt;( node, parent ); }}
  </code></pre>
  
  <p>Can anyone tell me what clang is seeing here?</p>