title: std::move with std::shared_ptr in lambda
body: <p>I have a strange issue when moving <code>std::shared_ptr</code>s in lambdas. I am not sure if it is a bug or not, as I can reproduce with g++ v6.3 and clang++ v3.9.</p>
  
  <p>When I compile and run the following program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  void f(std::shared_ptr&lt;int&gt; ptr) {
    std::cout &lt;&lt; 3 &lt;&lt; " " &lt;&lt; ptr.get() &lt;&lt; std::endl;
  }
  
  int main() {
    auto ptr = std::make_shared&lt;int&gt;(42);
    std::cout &lt;&lt; 1 &lt;&lt; " " &lt;&lt; ptr.get() &lt;&lt; std::endl;
  #ifdef LAMBDA
    auto lambda = [ptr]() {
  #endif
      f(std::move(ptr));
      std::cout &lt;&lt; 2 &lt;&lt; " " &lt;&lt; ptr.get() &lt;&lt; std::endl;
  #ifdef LAMBDA
    };
    lambda();
  #endif
  }
  </code></pre>
  
  <p>with the command <code>c++ -std=c++14 -o test main.cpp &amp;&amp; ./test</code> yields something like</p>
  
  <pre><code>1 0x55a49e601c30 1
  3 0x55a49e601c30 1
  2 0 0
  </code></pre>
  
  <p>However, changing the compilation command to <code>c++ -std=c++14 -o test main.cpp -DLAMBDA</code> makes the execution print something I cannot explain:</p>
  
  <pre><code>1 0x55a49e601c30 1
  3 0x55a49e601c30 3
  2 0x55a49e601c30 2
  </code></pre>
  
  <p>So, it appears that the <code>std::move(move)</code>, when performed inside a lambda, does not actually cause the <code>shared_ptr</code> to be moved, nor does it prevent its reference counter to be incremented.</p>
  
  <p>Again, I can reproduce this with clang++ and g++.</p>
  
  <p>How is that possible?</p>