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

    <tr>
        <th>Summary</th>
        <td>
            overzealous `-Wconditional-uninitialized` with known state of conditional code
        </td>
    </tr>

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

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

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

<pre>
    ```
#include <string>
#include <vector>

int func(const char*);

extern void f(const std::string &file);
void f(const std::string &file)
{
    const std::vector<std::string> filenames = {file};

    int err;
    for (const std::string & f : filenames) {
        err = func(f.c_str());
        if (err == 0) {
            break;
        }
    }
    if (err != 0) {}
}
```

```
<source>:18:9: warning: variable 'err' may be uninitialized when used here [-Wconditional-uninitialized]
   18 |     if (err != 0) {}
      |         ^~~
<source>:11:12: note: initialize the variable 'err' to silence this warning
   11 |     int err;
      | ^
      |             = 0
```

https://godbolt.org/z/6ET1dnvYf

`filenames` is always non-empty so `err` will always be assigned and is never not initialized.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVE2PqzgQ_DXNpZUIbD7CgQOTSX7BSqs9rQxugvc59sg2ZOcd3m9fmZBkJjN6WhRBbKq6q8othPfqZIgaKF6geE3EFEbrmkE5uoiZks7K9wbKdP2lLTCuTK8nSQh874NT5gT88OXNTH2wbn2TtsoEHCbTA9v11viA_SgcsBZYDfzliqF_AzmDs1UShzvQBwm8Bd5eeyGwclCa7sT_D09bqCIDEfEJfFO7f6IDP2CkG3Emj8BfEaqXpV71etcd60V_5Nx1L24M1uHvROGAwNtHcWA1PuTFi5xbOq6xDdv-bx8csF30cnN_A6shdlspkZV-LRivzpH48ZkarVxXj38fyrHsU7kFst4_jsXTku-9nVxPcQB4m-2At3X0exHOLLm2OAunRKcJgVUxOlbhWbxjRzgZZVRQQqufJPEyksHJk8SRHCEUL5s_e2ukCsoaoTef0FCsFrIdQrV_zuY7M7cU9veQoDj8-vWNiyzeWNRubKD4fHTGMNJ3loJFH8-4jwjl7wFcRWYPkc8DdJUExeFbict6sfLlHMYQ3nwcN3YEdjxZ2VkdttadgB1_AjuWhz8yaea_hvuxPYawTFF5FPoi3j0aazZ0fgvv6C1CmUZ5ZYoXpfUN0hGuXxCJwshINjSTiwF9CEduE9lwWfNaJNRkVV6zLC1rloxNKsssE90uY_nAWFd1dZ6nokirXVmWvOaJaljKirRMyywrMs62eU9lWe-klCTzXVFAntJZKL3Vej5Hn4nyfqImy3nGskSLjrRfvm-M9VoswyeVOBnrg-o9MAZsD4wNQnvavFmvgpopbheviWti1U03nTzkqVY--EefoIKmxs7kfpLQdvIxpd8N55JeGPGHsReDPohAaAf8QMDeSkomp5unY1RhnLptb8_AjlHA-ti8OfsP9QHYcXHtgR1X43PD_gsAAP__YXK2Dw">