33 lines · plain
1.. title:: clang-tidy - bugprone-infinite-loop2 3bugprone-infinite-loop4======================5 6Finds obvious infinite loops (loops where the condition variable is not changed7at all).8 9Finding infinite loops is well-known to be impossible (halting problem).10However, it is possible to detect some obvious infinite loops, for example, if11the loop condition is not changed. This check detects such loops. A loop is12considered infinite if it does not have any loop exit statement (``break``,13``continue``, ``goto``, ``return``, ``throw`` or a call to a function called as14``[[noreturn]]``) and all of the following conditions hold for every variable15in the condition:16 17- It is a local variable.18- It has no reference or pointer aliases.19- It is not a structure or class member.20 21Furthermore, the condition must not contain a function call to consider the22loop infinite since functions may return different values for different calls.23 24For example, the following loop is considered infinite `i` is not changed in25the body:26 27.. code-block:: c++28 29 int i = 0, j = 0;30 while (i < 10) {31 ++j;32 }33