<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/132038>132038</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang++]: Incorrect warning emited for [-Wfor-loop-analysis]
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
greg7mdp
</td>
</tr>
</table>
<pre>
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);
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVEGPszYQ_TWTyygR2CGEAwfyZSP13MMeI2NPwJWxkW3y7V72t1cmbIhafap6qGohYY1n3pj3hidC0J0lqqE4QXHeiCn2ztedp64c1Lhpnfqs34W32nYonfcko_nEEEWkgLEXEWNPeBdei9ZQQOEJrYs4OKVvmhRqO2cY50ZMaMB-YDtFhEPWk-76CIcMdUBtpaeBbCSFlu7kY0-GQkBgxwUj1aS061poxNAqAaxCYdXaSAe8aUs7yBrImt-JkD7EMBrC0bvOiwF48ziDQ7Y8WQPsAuyC0g2jNoQ_dexTS2mE7YCdgJ22LMNtiAr4WT4iKfAujMGtnFvv5Di-oq2wX8AucRgR3hhUZ2gu-O-Bn2DPCG_yDHjDC-AN_nwIlbarIsDKhS9WziwBK8mq6xqcwkOnmTrprNJRO_s3GZ8SIhSn7fvN-W0KbYUV5jPoAMV5vSAi5hlC-SPtbs4nGSdtI2fXiGt7BH5GVgI_4TPwI8VebshP-Ko6OwKr0vPaC_G71z8sKN6-0kr7r-dasfJvErEjS15EUrv1dPv_r_kyXFtpJkWJLRmi0jYCf3tMNH1E8hbvTisUSl2ju9LHSDKSusY0Eq9K9IlIfnpUziWRwsIxQpkOEHFNX0XLnmWIKKboXkWaM5KlsMOiWnFeQfEx4au8UJ5f0f6rcXlMwK84-c7_5qM8_8UeNqrmquKV2FCdl3vGq31ZHDd9Lfei2heZynMpb7nkQsi2OBwrdSh4W5Vyo2uWsSLjeZXvOePHnbzleyoKzouSyrJSsM9oENrsjLkPO-e7jQ5hojrnLOPHjREtmTB7NGOLa7Bk175OBdt26gLsM6NDDCtE1NHMxv7iM0kH3uBvdvHy57TToJPzztT_6u_eTN7UfYxjSPY5_xGdjv3U7qQbgF1S5-W1Hb37g2QEdpm_JAC7LB9zr9mfAQAA__8STOLe">