title: Temporary object argument lifetime in a function
body: <p>I've read several posts about temporary object's lifetime. And in a word I learn that:</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/37946437/when-exactly-does-the-destruction-of-a-temporary-object-happen-in-a-function-cal">the temporary is destroyed after the end of the full-expression
    containing
    it.</a></p>
  </blockquote>
  
  <p>But this code is out of my expectation:</p>
  
  <pre><code>#include &lt;memory&gt; 
  #include &lt;iostream&gt; 
  
  void fun(std::shared_ptr&lt;int&gt; sp)
  {
      std::cout &lt;&lt; "fun: sp.use_count() == " &lt;&lt; sp.use_count() &lt;&lt; '\n'; 
      //I expect to get 2 not 1
  } 
  
  int main()
  {
      fun(std::make_shared&lt;int&gt;(5));  
  
  }
  </code></pre>
  
  <p>So I think I have 2 smart pointer objects here, one is <code>std::make_shared&lt;int&gt;(5)</code>, the temporary unnamed object and the other <code>sp</code> which is a local variable inside the function. So based on my understanding, the temporary one won't "die" before completing the function call. I expect output to be 2 not 1. What's wrong here?</p>