<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94799>94799</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
FR: Warn on copy when corresponding move op exists and the source is never used again
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pkasting
</td>
</tr>
</table>
<pre>
Code like the following is a common source of extra copies in Chromium:
```
void f1(T t);
void f2(T t) { f1(t); }
```
When `T` has a move constructor, the caller presumably would have liked to invoke it.
The generalization of this is: I'd like to find code that has a `T`, copies from it (when a corresponding move op exists and isn't equivalent), and never reads from the source object again before it goes out of scope.
The case where this would fall down is if the read happens in a way the compiler can't detect, e.g. through some kind of pointer aliasing. This is almost never the case in practice in Chromium at least, but I'm not sure what sorts of safeguards need to be present.
To me this is such a clear pessimization that, like -Wpessimizing-move, it deserves a (possibly off-by-default) warning. But if I'm wrong, I would take a clang-tidy pass too.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyElM2O6zYMhZ9G2RAJHOV_4cX8IMDdFgPMmrZoW3dk0RXp5KZPX8h22kFboECQIKEinnP40Sji20hUmsOrObyvcNSOUzl8oaiP7api9yjf2BEE_0WgHUHDIfDdxxa8AELNfc8RhMdUE3AD9EtT_nnwJOAjvHWJez_2ZvdiindTvJhjsbymr3Bj76DZGnv-ADX2YnavS2Up2b9KYE6v89HlIJjT-3_eOr9_dhTBHIsPcyygw6y35xtBzVE0jbVyMvZtslVjCJRgSCRjj1V4wJ3H4KDD22zegTL4eOMvAq-b720-OoKWIiUM_g9UzzEHoZ0X8GJ2L_DD2JNbImRofHRQ51C1Q110LSqznCW7JnEPXsHY8z37yKGmRDJwdDn-yQkPQL-8qABGB16isScF-n30NwwUp5js21SMdKMEidAtd2fbz7lVP6lWwBZ9hIoaTtkktEwCPGq2IzUP9C_bNQrBvaNEs985tAZDAMf3mBnxzdQpN4YOh4HixAXCHR9z9NwPPodf4yzfkVKtWTdt2g1ol3hsOxDuCb5yeNzAwD4qJcDgUXxsN_Ax5w0YehZd7OpTo48wJKzV1_SdSkCFQChTt2rUaVQ9RFaQMWVrqCCcVKYMsKF2xOQEIs1EVDQxQ_EfSDD09EQAZKy7PL9AmGAgEd8_QckI5N4THOvPZ9HHdp0HnEs-JyKUbjSBYs8Di_iMKDfNunqsHTU4hmlB7pjilMbrqDn52c49cWzzVT-WASl-0SQIY7tW7x4woAgo82blyp277C64onJ72p5Ol-3uvF915Z4Op8PWEhYNNfvz4Xzc253FYlsUtjpW25UvbWH3xbE42WJ7tPuNuxwPzlV1syvOB9xezL6gHn3YhHDrN5zalRcZqbzsT5fLKmBFQZ5PolTmQ-tqbMXsi5AR__tv6jVQef0t79Ynpggc89Y8YFqU_12Tb-B7WUAZhdzM_2pMoexUh7y6xl6NvbZeu7Ha1Nwbe80qlo_1kPjnhOp1ciLGXmczt9L-GQAA__-eiMYX">