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

    <tr>
        <th>Summary</th>
        <td>
            clang doesn't report unused variables initialized in if statements
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Consider the following code:

```c++
int main( int argc, char** argv ) {
    if( auto unused = argc > 1 ) {
        int alsoUnused = 0;
    }
}
```

Both `unused` and `alsoUnused` variables are initialized, but not used. gcc is able to report this correctly:

```
% g++ -Wall test.cpp
test.cpp: In function ‘int main(int, char**)’:
test.cpp:3:21: warning: unused variable ‘alsoUnused’ [-Wunused-variable]
    3 |                 int alsoUnused = 0;
      |                     ^~~~~~~~~~
test.cpp:2:18: warning: unused variable ‘unused’ [-Wunused-variable]
    2 |         if( auto unused = argc > 1 ) {
      |                  ^~~~~~
```

With clang (15.0.7) you only get warning for the `alsoUnused` variable. The variable initialized in the if statement is not seen as unused.

```
% clang++ -Wall test.cpp
test.cpp:3:7: warning: unused variable 'alsoUnused' [-Wunused-variable]
                int alsoUnused = 0;
                    ^
1 warning generated.
```

Since `unused` is not used anywhere, it would be nice if clang could report that.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVV2PqzYQ_TXDyygITPh64CG72Uh9bqt9NmYAV44d2Waj9KG_vTKEJPtxu_cWocSMfcZz5hwMd04OmqiB_AnyfcQnPxrbnI3qT6qLWtNdmmejnezIoh8Je6OUOUs9oDAdQbaDZA_J-lskyy2APYV7jkrt8cilBlZhGHM7CGDPKEZuge2A7ULoDYHVCOUVhIgo-wDhkzc46clRh5DtZzhC9oLpZ8SMClsoZ_68QxLIHhZBub-WexusdT-SeTJ-RCiSZWsoEuS6C4F78hB841byVpFDbgmlll5yJf-mLlBsJ4_aeAyLYxyEQOkwrEZv0NLJWI9-lA6FsZaEV5cfdfT6yHIclt7i5pUrhZ6cj8XptMzfnrId_qaxn7Tw0miEFwZVAnX1oIXU_r0KwOp1XX0r4yFjBtmOpSH1mVst9RCGV2HWLtx3eujSmhQhf9q8LojNioB8f5cmQyif8eP1raL4JWyO5y__rNcnQgyyXVr9LKHpV8mwd1X9HzN_yWql9B_WfZV-RKG4HhBYleZxEpch_cVMaLS64EB-5Yy9Wd7sHzo7xj9GujfkweIo9QyVPTrPPR1J--DwYHlHpJG7K9n4G1PPxf6csYMNy-9EY-UDF1Z-L9Yv-u2TJMtkeuvqQJos93fmX-n0u9SC3p8x1-7NG3N9OY9kKbym0uPZTKrDllBLMfd8UVjM4dthwn0cdU3W1VnNI2rSoqyLoiyKNBqbsq-LvK5a2nas4FVJacLarch7UW3TlspINixhWZKxbbplaZLGnagzkdG2L8o2y_oCtgkduVSxUm_H2Nghks5N1BRpUaWR4i0pN39LGNN0xnkSGAufFtsEzKadBgfbREnn3T2Ll15RsxDqDDkNrPQrqQ_quo8WfLSfiyarmtH7kwtnGDsAOwzSj1MbC3MEdghbXv82J2v-IuGBHeZCHbDDTOTfAAAA__9xjhL4">