legrosbuffle wrote:

> Shouldn't this case be already covered by

No, this case is different: note that the `std::move` is already present.

With

```
void NegativeMoved(ExpensiveToCopyType A) {
  ExpensiveToCopyType Copy = std::move(A);
}
```

If the caller passes an lvalue (case L), there is one copy (in the caller) and 
one move (in `NegativeMoved`). If the caller passes an rvalue (case R), there 
are two moves: one in the caller, and on in `NegativeMoved`.

The check currently suggests:

```
void NegativeMoved(const ExpensiveToCopyType& A) {
  ExpensiveToCopyType Copy = std::move(A);  // Note: move becomes useless.
}
```

With this code, we always have a copy in both cases L and R, because 
`std::move` yields a `const&&`, which selects the copy ctor. There is no way 
for the caller to benefit from having an rvalue.

Given that move is typically much cheaper than copy, there should never be a 
reason to pick the second version, especially given tha the user expressed 
their intent to move.








https://github.com/llvm/llvm-project/pull/145871
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to