Closed
Description
https://godbolt.org/z/YPd4h3xPn
#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.