$ account include-what-you-use
include-what-you-use (IWYU) is a Clang-based static analysis tool for C/C++ that enforces minimal and correct `#include` directives. It analyzes every symbol used in a translation unit and ensures that the file directly includes the header that provides that symbol, suggesting removal of unused includes and addition of missing ones. The tool is designed for integration into build systems (e.g., CMake, Make, or via a compilation database driver) and can generate automatic fixes through its companion script `fix_includes.py`. The architecture is a pipeline: the Clang preprocessor and AST callbacks (`IwyuPreprocessorInfo`, `IwyuAstConsumer`) track macro expansions, symbol references, and template instantiations. A core component is the `IncludePicker` which maintains a large built-in map of symbol-to-header and private-to-public header mappings (for libc, libstdc++, libc++, Clang builtins) and supports user-supplied mapping files in YAML/JSON format. The analysis output is structured text that `fix_includes.py` parses to rewrite source files. The codebase is thoroughly tested with hundreds of small regression tests and a large monolithic test (`badinc.cc`), plus unit tests for internal utilities. IWYU is tightly coupled to Clang's AST and preprocessor APIs, requiring regular updates to track Clang mainline. Despite this, the project maintains a sophisticated handling of C++ complexities: templates, alias templates, forward declarations, macros, inline namespaces, and pragmas for manual override. The mapping system is extensible and includes generators for popular libraries (Boost, Qt, Python, Windows SDK). The tool is mature enough for production use in large codebases, though it acknowledges some known limitations (marked as `IWYU_XFAIL` tests).