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

    <tr>
        <th>Summary</th>
        <td>
            clang-tidy: misc-include-cleaner: Unused includes not removed from .h file
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    In the attached example, unused includes `#include <stdio.h>` and `#include <inttypes.h>` are not removed from `number_generator.h`.

These are the steps to reproduce:

```
# Extract the attached archive
tar xvf test-includes.tar.gz
cd test-includes

# Build the example program (compilation database is also created in the process)
mkdir build && cd build
cmake ..
cmake --build .
[test-includes.tar.gz](https://github.com/user-attachments/files/17544736/test-includes.tar.gz)

run-clang-tidy-18.py -header-filter='-*' -checks='-*,misc-include-cleaner' -fix

# Observe that number_generator.h still contains `#include <stdio.h>` and `#include <inttypes.h>`, despite being unused.
```

(Note that the attached example as well as the steps to reproduce are identical to issue https://github.com/llvm/llvm-project/issues/113926.)

Thank you.

[test-includes.tar.gz](https://github.com/user-attachments/files/17544830/test-includes.tar.gz)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VM2uszYQfRqzGYGInUCyYHF_vkit1HbzdV0N9gTca2xkD-lNn74CEt2_qF20lZCtwXPs4zNnjCnZzhM1Yvcods8ZTtyH2PyI_ifkp2Aw2TFrg7k0P3jgngCZUfdkgF5xGB0J-QSTnxIZsF67yVACUZVCqmsIQj0lNjYUvVDfRFUCevM1xXrmy0jpLSsS-MAQaQhnMnCKYZhhfhpair915Ckih1j0oioLUT6L8mEdv_eUaMHPhBPTmIADRBpjMJMmoR7ep89U1m8NpYJvrxxR88cLY9S9PdOaxRjh9XwCpsT57eIFYyy6P9cMbT4ufjhSKnicrDPLCVclYYyhiziAkHsdhtE6ZBs8GGRsMRHYBOhSAB0JedF7gY8xaEpJyMO6-fBibIR22V7ISsgKtFnjK7MBXwiK4n2U5yvgJuTu8e7Nds9C7nvmMc0iyqOQx85yP7WFDoOQxylRzFfFBvKchDyerKN53tS77bZWlZDHu1vf6K9jnHyuHfouZ2su-WZfjBfIe0JDMT9ZxxSFehayzoV8ELKGXPekX9L7n0-DTfp2Tq4doae45J7s6-dy_NImiufZMsjw1WOQ2DoHOnhG6_8bi8-tYyiNlglasr67NlJx35dXqvufA19p3utHwAR_kHPzfN_-S2dYQ56tRjcv2ZQmgr8pq3Pn25SPMfxOmoU8LrCltBt1kFXxqYTfe_QvcAnTh-b8v5y1V-U_OSszjTIHdcCMmk2tyo08bMsq6xtFuqYN6r3Wh3ZPplTydKq12quDRqOqzDaylNtNKfebnSrLqthhWdeqrdqqrM0BT2Jb0oDWFbNERYhdtojTLMrUmcOWXLq9sbFZhGynLolt6Wzi9IZjy46aN-sL9QB3fawe4NdP7-6X57LoYRYpm6Jr_mV56-zcyL8CAAD__xC7-JA">