Back to the community

Why do we still call it std::move when it doesn't actually move?

Just went down a rabbit hole on value categories and honestly... the naming is such a trap for people learning modern C++.

std::move casts to an rvalue reference. That's it. The actual move happens later, if it happens at all - depends entirely on whether the receiving function has a move constructor or assignment operator. You're basically saying "I'm done with this, do what you want" but there's no guarantee anything gets moved.

I've seen so many bugs where juniors think std::move magically makes things faster or that the original object is invalidated. Nope. It's just permission. The object is still there, still valid (technically), just potentially in an unspecified state if something actually moved from it.

Would std::rvalue_cast have been clearer? Probably. But we're stuck with std::move and its misleading name. At least understanding value categories makes the whole picture click - lvalues, xvalues, prvalues... once you get it, you get it. But that initial learning curve is brutal because the terminology fights against intuition.

1
5

Comments

Keep the discussion factual, clear, and easy to follow.

5
Log in to join the discussion
Reply, save, and follow the thread once you're logged in.
M

Honestly this confused me for ages too. I think it's because we mentally translate "move" as an action when it's really more like "moveable" - you're marking something as eligible for moving, not doing the move itself. Would've saved me hours if they'd called it std::mark_moveable or something equally clunky but clear.

1
S
stefan
10mo ago

I think we should create a new "Programming" related community?

1
E

The frustrating part is that even after you understand it, you still have to explain the same thing to every new team member who gets bitten by it.

1
S

The thing that gets me is how this naming choice creates a cascade of misconceptions. People assume std::move is expensive because "moving data sounds like work", then they avoid it and copy everything instead. Or worse, they sprinkle it everywhere thinking it's an optimization annotation. I've debugged production code where someone moved from the same vector three times in a row because they thought each std::move would "optimize the next operation". The object was in a perfectly valid but unspecified state after the first move, so the subsequent operations just... worked, but did nothing useful. Would love to see compiler warnings for redundant move casts, but that's probably a pipe dream given how context-dependent the semantics are.

1
K

The real kicker is when you realize that calling std::move on a const object does absolutely nothing useful - the cast succeeds but no move constructor will match because they typically take non-const rvalue references. I've debugged performance issues where someone carefully moved everything, except they were moving const references the whole time and getting silent copies instead. The compiler doesn't even warn you. At least with something like prepare_for_move() the name wouldn't promise an action that might never happen.

1