<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/138842>138842</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] bugprone-infinite-loop false positive with structured binding
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy,
            false-positive
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          satorimarch
      </td>
    </tr>
</table>

<pre>
    clang-tidy's `bugprone-infinite-loop` check incorrectly flags a valid loop as infinite when using a structured binding declaration in the loop condition.

Code example:

```cpp
#include <iostream>

int main()
{
    int x = 10;
 auto [y, _] = std::pair<int, int> {1, 2};

    while (y < x) {
 y++;
    }

    return 0;
}
```

Command:

```bash
./build/bin/clang-tidy temp.cpp -check=-*,bugprone-infinite-loop
```

Output:

```bash
temp.cpp:8:5: warning: this loop is infinite; none of its condition variables (x) are updated in the loop body [bugprone-infinite-loop]
    8 |     while (y < x) {
      |     ^
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVN2OszYQfZrhZpTI2BDIBRck2dz2ESoDE5jW2Mg22c3bV85Ps9X3rSpZMp6xz3jOOUaHwKMlaqA8QHnK9Bon55ugo_M8a99PWeeGW9MbbcdN5OEGsgoIO9Gt4-KdpQ3bC1uOtDHOLbAT2E_U_41se-c99dHc8GL0GFDjVRseMO1DHfB1ED8nsrgGtiNqDNGvfVw9DdixHVJwoN5oryM7i2wxTvTA6J0dOEW3IFoQ7dENhPSl58UQqPYRhJ14jH5Z0lIqtr1ZB0JQR3YhetIzqI_HbrYRZ80WZA1yn2LVAUSLiJhSXwjqhLkAdY_qNTqE8nADecQ_oTzd0yEOqbpqF80-FbEx5dOkPhCqQ56WEqrTA-aJ_zmxIQRZ39LN8AvkHp_VbyAPaajXXdLZfw96iqu3-LzUM_Xq-sXMPGs7_EpKp8MEot2CPHcrmyHNqfvzW3CMNC_bfllwc1cW1GkDsgV5_MECv1T_Y43LGn8s_sIH1dag2hJUi5_aW7Zj-owTh4fe_PYMqANaZwndBTmGtxXwqj3rzlBIVN5J1J5wXQYdafiPfZKxk3o_tFGenvzWCNUR_0cifMjy2Aflx_c-s6FRw17tdUZNXhW7Xa72xS6bGpUXgupeKVEIJXRPdb3fV2VVDAVdqJIZN1LIUpSiyoWScrelQqmiLEul8mJPuxwKQbNmszXmOm-dHzMOYaUmV3VdyMzojky4P24pv79hCfIIUl60CbRZXODIV0rh8pT5JoFtunUMUAjDIYY3fORo7n-Lb2jlCX_PId7x8YWPnxyn3zzwbPWmmWJcQvKIPIM8jxyntdv2bgZ5TsWf02bx7i_qI8jzvdEA8vzs9drIfwIAAP__7Wh0aw">