title: return const reference vs temporary object
body: <p>I'm wondering why returning <code>const reference</code> of a local object is illegal whereas returning a <code>local object</code> is legal as long as you assign it to a <code>const reference</code>?</p>
  
  <pre><code>vector&lt;int&gt; f_legal() {
      vector&lt;int&gt; tempVec;
      tempVec.push_back(1);
      return tempVec;
  }
  
  const vector&lt;int&gt;&amp; f_illegal() {
      vector&lt;int&gt; tempVec;
      tempVec.push_back(1);
      return tempVec;
  }
  
  void g() {
      const vector&lt;int&gt;&amp; v1 = f_legal(); // legal
      const vector&lt;int&gt;&amp; v2 = f_illegal(); // illegal
  }
  </code></pre>
  
  <p>Edit:
  My point is that if assigning a const ref to a returned local variable is legal, then shouldn't assigning a const ref to a returned const ref of a local variable be legal as well?</p>