Hi, The new bugprone-infinite-loop check is not detecting some easy patterns of finite loops, thus leading to false positives. Not sure if this can easily be fixed: $ clang-tidy --version LLVM (http://llvm.org/): LLVM version 10.0.175git Optimized build. Default target: x86_64-unknown-linux-gnu Host CPU: broadwell $ cat .clang-tidy Checks: bugprone-infinite-loop $ cat x.cpp #include <iostream> int main(int /*argc*/, char** /*argv*/) { char foobar[] = "foobar"; char *pattern = foobar; while (char c = *pattern) { if (c == 'o') { std::cout << "o" << std::endl; } ++pattern; } return 0; } $ clang-tidy x.cpp /home/d067158/x.cpp:7:5: warning: this loop is infinite; none of its condition variables (c) are updated in the loop body [clang-tidy-bugprone-infinite-loop] while (char c = *pattern) { ^ $ ./x o o Best regards Dennis
Reduced test case: void false_positive() { int n = 10; while (int m = n) { --n; } } However, no false positive for this: void no_false_positive() { int n = 10, m; while (m = n) { --n; } }
Fix uploaded for review: https://reviews.llvm.org/D73270
(In reply to Ádám Balogh from comment #2) > Fix uploaded for review: https://reviews.llvm.org/D73270 That was committed, and later cherry-picked to 10.x in d275de35f8bdb92e7b5789ebdb96df99fab504ab