This warning will catch:
- Using std::move in a return where the moved object is a local variable
- Using std::move on a pr-value object
struct A {} A test() { A a = std::move(A()); // warn since A() is a pr-value return std::move(a); // warn since a is a local variable }
This looks familiar. Can some commonality be factored out here?
Or, better, can you implement both checks in a single place? When performing the initialization sequence, you can ask the initialized entity whether it's the returned object in a return statement.