title: Returning temporary object and binding to const reference
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2784262/does-a-const-reference-prolong-the-life-of-a-temporary">Does a const reference prolong the life of a temporary?</a>  </p>
  </blockquote>
  
  
  
  <p>My compiler doesn't complain about assigning temporary to const reference:</p>
  
  <pre><code>string foo() {
    return string("123");
  };
  
  int main() {
    const string&amp; val = foo();
    printf("%s\n", val.c_str());
    return 0;
  }
  </code></pre>
  
  <p>Why? I thought that string returned from <code>foo</code> is temporary and val can point to object which lifetime has finished. Does C++ standard allow this and prolongs the lifetime of returned object?</p>