There is no safe programming practice that would warn about this because executing a copy after std::move incredibly common and normal. Adding a warning will cause almost everything in the <algorithm> begin to warn of dismissal, and we will need a completely new function that we will use that works just like std::move . Many algorithms rely on copying if there is no move constructor, or moves in the reverse order, and std::move used for this. At best, you should argue about the existence of std::force_move .
Secondly, this is completely unnecessary. Take this modified version of the code you showed.
void legacy_api(A a1) { A a2 = std::move(a1); ...
You say that this is a problem, that she subtly used an expensive copy, and not a subtle move. I do not agree with what you need, this is a new instance of the object, potentially destroying the previous one. If the code needs another instance, it needs another instance. Regardless of whether it was destroyed by the previous one, it should be completely irrelevant. If the code moves when it doesnβt need another instance, then the lagacy API is clearly written from scratch, and the above warning will not help. I cannot think of any reason why the function will require moving, but there is no copy, there is no purpose for such a thing.
Finally, "Now two objects may have a pointer to one resource, while one of them will probably call it a destructor soon." No, if that happens, it means that A copy constructor has an error, period. Correct the errors in the code and the problems will disappear. Like magic!
source share