Issue 132038
Summary [clang++]: Incorrect warning emited for [-Wfor-loop-analysis]
Labels clang
Assignees
Reporter greg7mdp
    Warning correctly states that the variables are not modified in the loop body, but `height` is incremented nevertheless (in the  `incr_height` lambda) and the loop is fine.

See example program:

```
// compile with `clang++-20 -std=c++20 -Wall -c loop.cpp`
//
// ~/tmp ❯ clang++-20 -std=c++20 -Wall -c loop.cpp
// loop.cpp:10:35: warning: variables 'height' and 'end_height' used in loop condition not modified in loop body [-Wfor-loop-analysis]
//    10 |    for (uint32_t end_height = 27; height <= end_height; incr_height())
//       |                                   ^~~~~~    ~~~~~~~~~~
// 1 warning generated.
// -----------------------------------------------------------------------------------------------------------------------------------
#include <cstdint>

extern void add_to_expected_table(uint32_t h);

void test() {
   uint32_t height = 0;

   auto incr_height = [&height]() { ++height; };

   for (uint32_t end_height = 27; height <= end_height; incr_height())
      add_to_expected_table(height);
}
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to