§12.2/5 (my emphasis)
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 except:
- A temporary bound to a reference ...
- A temporary bound to a reference parameter in a function call (5.2.2) persists until the completion of the full-expression containing the call.
In the snippet below (live example) one can see that the temporary A()
is bound to the reference a
for the lifetime of the reference, that is, the destructor ~A()
is invoked at the end of the function f
.
#include <iostream>
struct A{
A() { std::cout << "A()" << '\n'; }
~A() { std::cout << "~A()" << '\n'; }
};
void f(A&& a) { std::cout << "f()" << '\n'; }
int main()
{
f(A());
}