<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/88617>88617</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] Add check for variable that can be moved but isn't
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sweemer
</td>
</tr>
</table>
<pre>
I would like to request a clang-tidy check for variables that can be moved but are not. For example, in the following code `string` can be moved into `f1` to save an unnecessary copy but there is apparently no check for it at the moment. Can it be added?
```c++
#include <string>
#include <utility>
#include <vector>
void f1(std::string string) {
std::vector<std::string> vector;
vector.push_back(std::move(string));
}
void f2() {
auto string = std::string();
f1(string);
}
```
```console
$ clang-tidy --version
Ubuntu LLVM version 19.0.0
Optimized build.
$ clang-tidy -checks=*,-llvmlibc-* move.cpp
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "move.cpp"
No compilation database found in /home/sweemer/test or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
39836 warnings generated.
Suppressed 39836 warnings (39836 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU2P4ygT_jXkUrJlQz4POWSSjvS-mu2RdjR7XWGoxExj8EI5meyvX4GT6XSm-zASSmSK56OgCmSM5ugQ12z2ic12EzlQ68M6nhE7DJPG68v6f3D2g9VgzQsCeQj4z4CRQIKy0h0LMvoCqkX1Agcf4CSDkY3FCNRKAiUdNAidP6GGZiCQAcF5KmHvA-AP2fUWGd-CcUAtwsFb68_GHUF5jcDmVaRg3JHNq7dcxpFP4UOdQuQhyhOCdDA4hwpjlOECyveXrEotBgQTQfa9DOjIXsD5O9uGQOZl0PkOHZWwlS7NNghSa9RM7Fm1Y9Xm-juvxqEY_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