legrosbuffle wrote:

Note that in the test I wrote I called a ctor for simplicity, but in general I 
want to avoid warning on anything that looks like this:

```
template <typename... Args>
void Eat(Args&&...);

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

The move ctor just happens to be a specific case of `Eat`.

If we wanted to be fully consistent we'd have to turn:

```
void NegativeMoved(ExpensiveToCopyType A) {
  Eat(A);
}
```

into:

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

We've actually had such a check internally for a few years (suggesting to 
`move` local objects, including parameters). This check is extremely complex 
(though it handles more cases than just a single reference to the parameter to 
make a copy, in particular it handles the case that @firewave mentions in 
[#57908](https://github.com/llvm/llvm-project/issues/57908). So I think 
suggesting the move is way beyond the scope of `unnecessary-value-param`. 
`unnecessary-value-param` happens to suggest the move in the very specific case 
of "a by-value parameter used exactly once as the argument of a copy 
constructor except if we're anywhere within a loop" , but that's a bit ad hoc 
and just there because it's a common pattern (in particular, in constructor 
init lists) that we don't want to pessimize.

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