No, the temporary will last until the end of the full expression containing the call to foo
, we can see this from the draft C++ standard section [class.temporary]p6 which says:
The third context is when a reference is bound to a temporary object.38
The temporary object to which the reference is bound or the temporary object that is the complete object of a subobject to which the reference is bound persists for the lifetime of the reference if the glvalue to which the reference is bound was obtained through one of the following:
...
and then says further down:
The exceptions to this lifetime rule are:
- A temporary object bound to a reference parameter in a function call ([expr.call]) persists until the completion of the full-expression containing the call.
....
which is the case we have here. For a clarification of until the completion of the full-expression
see What is the lifetime of a default argument temporary bound to a reference parameter?.