return by value assigned to const reference
<p>I was fixing another bug in some code and came across some code that I would have thought was a bug; however, this code compiles under gcc 4.4, 4.5, and 4.6 and appears to function as "expected".  Can anyone tell me if this is valid c++?</p>

<pre><code>struct foo {
     int bar;
};

foo myfunction(foo const &amp;orig) {
    foo fooOnStack = orig;
    fooOnStack.bar *= 100;
    return fooOnStack;
}

void myOtherFunction(foo const &amp;orig) {
    foo const &amp;retFoo = myfunction();
    // perhaps do some tests on retFoo.bar ...
}
</code></pre>

<p>If this is valid c++, does anyone know the rationale behind this being legal?</p>
