On Fri, 11 Dec 2015 19:52:08 -0000 (UTC)
Tobias Müller <
tro...@bluewin.ch> wrote:
[snip]
> No, nothing is moved here.
> There is exactly one objects and it lives on the stack of main.
> Everything else is just references to that.
>
> RValue references _don't_ imply moving. They are a useful tool for
> defining move constructors, but not more.
> They behave just like normal references, except that they only bind to
> rvalues. But they are still just references.
In the code given:
A& foo(A&& a) { return a; }
int main()
{
A aa = foo(A());
}
there are two objects not one. First, the temporary create by the call
to A(), which lasts until the end of the full expression in which it is
situated, and secondly the named object aa which lasts until the end of
main() and which is initialized by the temporary. The question is
whether the construction of aa is within the full expression within
which the temporary is created so that the initialization is valid. As
I understand it, it is, so the code is valid. If that is right (and to
be honest I would never bother looking it up because I would never
write code like this), this also means that the compiler might elide the
two objects into one, depending on whether the default constructor and
move constructor of A have observable side effects.
Chris