Issue 109083
Summary [clang-tidy] False positive modernize-loop-convert for index used with another container in lambda capture
Labels clang-tidy
Assignees
Reporter vient
    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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to