 <p>It's fine to return a reference as long as the object referred to is not destroyed before control leaves the function (<em>i.e.</em>, an automatic local variable or parameter, or a temporary created inside the function).</p> <p>In this case, you are potentially returning a reference to the temporary <code>Foo()</code> in the <em>calling</em> context, which is fine because that temporary is guaranteed to survive until the end of the full-expression containing the call. However, the reference would become dangling after the full-expression, <em>i.e.</em>, the lifetime of the <code>Foo()</code> temporary is not extended, so care must be taken not to access it again after that point.</p>