You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
The text was updated successfully, but these errors were encountered:
EugeneZelenko
added
clang:diagnostics
New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
and removed
clang
Clang issues not falling into any other category
labels
Mar 19, 2025
Warning correctly states that the variables are not modified in the loop body, but
height
is incremented nevertheless (in theincr_height
lambda) and the loop is fine.See example program:
The text was updated successfully, but these errors were encountered: