title: Understanding const reference in assignment when constructing object
body: <p>Today I see this piece of code and I'm wondering to know what it is exactly doing this const reference in an assignment where a new object is created. (I don't know how to name this kind of assignments.)</p>
  <pre class="lang-cpp prettyprint-override"><code>std::string const&amp; p = s.c_str(); // s is a std::string
  </code></pre>
  <p>I understand that something like <code>std::string const&amp; p = s;</code> will create a reference <code>p</code> to <code>s</code>, but in the line shown we are creating a new object (using the raw pointer from <code>std::string::c_str</code>).</p>
  <p>I've made a MCVE in <a href="http://coliru.stacked-crooked.com/a/d4353c4b23f0a670" rel="nofollow noreferrer">Coliru</a> with this:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  void foo(std::string const&amp; s)
  {
      std::string const&amp; p = s.c_str(); // &lt;&lt; here
      
      std::cout &lt;&lt; s &lt;&lt; &quot; &quot; &lt;&lt; p &lt;&lt; &quot; &quot; &lt;&lt; &amp;s &lt;&lt; &quot; &quot; &lt;&lt; &amp;p &lt;&lt; std::endl;
  }
  
  int main()
  {
      foo(&quot;hello&quot;);
  }
  </code></pre>
  <p>And, as expected the output is showing that a new object was created:</p>
  <pre><code>hello hello 0x7ffdd54ef9a0 0x7ffdd54ef950
  </code></pre>
  <p>So, my question is: <em>Is this actually doing something I'm not able to see? Does it have any problem (like a dangling reference) in the code?</em></p>