[clang-tools-extra] [clang-tidy] unnecessary-value-param: Allow moving of value arguments. (PR #145871)
Clement Courbet via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 26 06:57:55 PDT 2025
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
More information about the cfe-commits
mailing list