[cfe-dev] Use-after-move warning?

Seth Fowler mark.seth.fowler at gmail.com
Mon Oct 6 13:26:35 PDT 2014


Hi all,

I recently got bitten by a bug that was caused by using a value (more specifically, returning it from a function) after moving it. Since this move happened only within one rarely executed conditional branch of a fairly large function, it wasn’t visually obvious why the behavior was different from what I expected, and it took me some time to track the issue down.

Obviously using a value after moving from it is legal C++, but in my own experience with using std::move, code like this almost always indicates a bug, or at least bad style. I’m curious whether others feel the same way. If use-after-move is only rarely useful, it would be nice to print a warning when it happens, perhaps with a way to disable the warning by using more explicit syntax (similar to how the warning for assignment in an ‘if’ conditional expression works).

If there was a patch to implement this, would there be support for including it in clang?

Thanks,
- Seth



More information about the cfe-dev mailing list