title: Do *non*-const references prolong the lives of temporaries?
body: <p>Once upon a time, I assumed that code like this would fail:</p>
  
  <pre><code>const MyClass&amp; obj = MyClass();
  obj.DoSomething();
  </code></pre>
  
  <p>because the MyClass object would be destroyed at the end of its full-expression, leaving obj as a dangling reference. However, I learned (here) that this isn't true; the standard actually has a special provision that allows const references to keep temporaries alive until said references are destroyed themselves. But, it was emphasized, only <em>const</em> references have this power. Today I ran the code below in VS2012 as an experiment.</p>
  
  <pre><code>struct Foo
  {
      Foo() { std::cout &lt;&lt; "ctor" &lt;&lt; std::endl; }
      ~Foo() { std::cout &lt;&lt; "dtor" &lt;&lt; std::endl; }
  };
  
  void f()
  {
      Foo&amp; f = Foo();
      std::cout &lt;&lt; "Hello world" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>The output when calling <code>f()</code> was:</p>
  
  <pre><code>ctor  
  Hello world  
  dtor  
  </code></pre>
  
  <p>So I had a look at the C++11 draft standard, and only found this (§ 12.2/4):</p>
  
  <blockquote>
    <p>There are two contexts in which temporaries are destroyed at a
    different point than the end of the full-expression. The first context [doesn't
    apply]. The second context is when a reference is bound to a
    temporary. The temporary to which the reference is bound or the
    temporary that is the complete object of a subobject to which the
    reference is bound persists for the lifetime of the reference.</p>
  </blockquote>
  
  <p>The word <code>const</code> is conspicuously absent from the above. So; has this behavior been changed for C++11, was I wrong about the <code>const</code> thing to begin with, or does VS2012 have a bug and I just haven't found the relevant part of the standard?</p>