Lifetime of temporaries
<p>Below code shows lifetime of object created in function <code>create()</code> is extended to the life time of <code>const ref</code> created in <code>main</code>, <em>is this correct in all cases</em>? I mean we can extend the life time of temporary in certain cases by creating a reference to it? Or in this specific case the compiler is misbehaving?</p>

<p>It is compiled with MSVC2005</p>

<pre><code>#include &lt;iostream&gt;

class testClass
{
public:
    testClass()
    {
        std::cout &lt;&lt; "in testClass " &lt;&lt; ((void*)this) &lt;&lt; std::endl;
    }

    ~testClass()
    {
        std::cout &lt;&lt; "in ~testClass " &lt;&lt; ((void*)this) &lt;&lt; std::endl;
    }
};


testClass create()
{
    return testClass();
}


int main()
{
    {
        testClass const&amp; obj = create();

        std::cout &lt;&lt; "we got a const reference to obj " &lt;&lt; ((void*)&amp;obj) &lt;&lt; std::endl;
    }

    return 0;
}
</code></pre>

<p>Output</p>

<pre><code>in testClass 0018FF13
we got a const reference to obj 0018FF13
in ~testClass 0018FF13
</code></pre>

<p>Of course other may get different addresses...In above case i was expecting destructor for the object created with function <code>create()</code>, will be called before line </p>

<pre><code>std::cout &lt;&lt; "we got a const reference to obj " &lt;&lt; ((void*)&amp;obj) &lt;&lt; std::endl; 
</code></pre>

<p>is executed.</p>
