Comment by knorker

7 hours ago

When talking C++ move semantics it's easy to talk past each other. So I'm not sure what your claim is. Another commenter said that one can tell if something is moved or not without looking at the body of the callee. Is that what you're saying? Because you can't.

I apologize if you're making a different claim, but I'm not clear on what that is.

Anyway, for my point, here's an example where neither copy nor move happens, which one can only know by looking at the body of the callee: https://godbolt.org/z/d7f6MWcb5

By changing only the callee we can cause a move: https://godbolt.org/z/b8M495Exq

Equally we can remove the use of `std::move` in the callee, and now it's instead a copy. (of course, in this example with `unique_ptr`, it means a build failure as `unique_ptr` is not copyable)

> [assignment or construction of a variable] happens at one place

Not sure what you mean by that. The callee taking an rvalue reference could first copy, then move, if it wants to. Or do neither (per my example above). Unlike in Rust, the copy/move doesn't get decided at the call point.

You can, at one point, statically determine if the (usually const) single ampersand reference function is called, or the rvalue reference function, via standard polymorphism. But that's not the point where the move cons/assign happens, so for that one has to look in the callee.

Calling a function that takes a rref will never use a move constructor to create the parameter. We can statically know that both of your foo functions will not use a move constructor when constructing p.

>By changing only the callee we can cause a move

This move is for constructing t. p still is not constructed with a move constructor.

  • p in the callee is not constructed at all. It's a reference.

    > Calling a function that takes a rref will never use a move constructor to create the paramete

    This is what I mean by talking past each other. This is literally what I said.

    Well, I wouldn't say the parameter is "created", since I'd say that's an imprecise term in this context.