[llvm] Remove unused standard header inclusion: <iterator>, <utility>, <type_traits> (PR #167318)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 10 12:49:10 PST 2025
serge-sans-paille wrote:
On Mon, Nov 10, 2025 at 12:06:20PM -0800, Kazu Hirata wrote:
> @kazutakahirata approved this pull request.
>
> LGTM. Thanks!
>
> Before you go, may I ask how you find these unused headers? Run IWYU and just
> takes a subset of its suggestions? I'm asking this because clang-tidy has
> misc-include-cleaner, but it does not remove things from header files.
I have a home-grown, stupid but surprisingly efficient script that performs the
following:
- hard code the list of « symbols » (types, globals, functions etc)
officially exported by each header.
- grep (...) for those symbols in each source file that includes a particular
header
- if a source file includes a header but does not reference any symbol, then
that header can be removed. If it was carrying a transitive dependency, then
this might break compilation and I fix it manually.
This approach brings some false negative but very few false positive (could be
possible if some symbol name is built by the preprocessor though).
I generally manually review the changes to make sure everything is good.
https://github.com/llvm/llvm-project/pull/167318
More information about the llvm-commits
mailing list