<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109083>109083</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] False positive modernize-loop-convert for index used with another container in lambda capture
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vient
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/YPd4h3xPn
```cpp
#include <cstdlib>
#include <vector>
struct A {
void f(std::vector<double> &v) {
for (size_t i = 0; i < v.size(); ++i) {
[[maybe_unused]] auto l = [x = std::move(vv[i])]() {
return x;
}();
if (v[i] == 0) {}
}
}
std::vector<float> vv;
};
```
produces
```
<source>:6:9: warning: use range-based for loop instead [modernize-loop-convert]
6 | for (size_t i = 0; i < v.size(); ++i) {
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| (double i : v)
7 | [[maybe_unused]] auto l = [x = std::move(vv[i])]() {
8 | return x;
9 | }();
10 | if (v[i] == 0) {}
| ~~~~
| i
1 warning generated.
```
without considering that capture `[x = std::move(vv[i])]` uses `i` to index another container.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VUuP4jgQ_jWVSwmU2CQhhxx4NOe57mnk2AV4ZWzkR6a7D_vbVw403bNktXPYsVCwq_zV4_OXWISgT5aoh3oL9b4QKZ6d70dNNhaDU2_9OcZrAL4BdgB2ODk1OBOXzp-AHd6BHf74plZn_vrNQrmHcnN_NuXtJ6_Xu4VxbaVJihD4ToaojB6Av8x5R5LR-U_n9AzRJxlxg9BubxZExNFphUdg6xBVLpJvPsA75dJgCPgLAmtGYN3PyDyOzmPG6nf6HlEj8D2WwLfTdIfjMnuArYF12QpsC2yrZ0PlMXG4vYi3gb4nmwIpqPdQ71Gk6NBM4aHevk6TR8EXN-Yc4wj1VmcA66bn-uc8nmLyFl-Bz2Vu948yn736mLv8iJ-z3xq9x2_3d8jn7B7yC_3Z9Mzx0TgRM8Xj-MicgY_5hw5uy6t3KkkKs07gu-CSl_nIgG8a4JsO-AZ_CG-1PeVpCoRe2BMtBhFITednnLuitiGSUJndi1PkrX6nRfYspLMj-ZgZffTRILQ7_N9F8DUo1C_413-NfwNPa7a-CXgqY4NZwPf97fPm3ym89VO6PGbl2D1XNifMqpz2_aosZ_nJY45DfTNUH7LBE1nyIpJazqruh45nlyJKZ4NW5DMknkVEKa4xecK881epa8os0ZAxOi-iQ20VvaKwLp7J5yxRaEt-Waieq453oqC-alnTcM66tjj3vGIlZ13TyLbiou6I6FgdealYzdVK8kL3rGSrsqvW5YpVvF02jWw4W3Ema2LHhmBV0kVoszRmvOQvdaFDSNRXZVeueWHEQCZMH3zGpBH2tIhavQFj-QLwfUYthnQKsCqNDjF8xok6mumq-AKr93gQJhBeXdBRj4Tzb-D0nt3YyALFTPwzL6gtGnEZlHgcQJG8-ectpOM5DUvpLsAOubr73-Lq3Z8kI7DD1HIAdrh3Pfbs7wAAAP__BLzngg">