[libcxx-commits] [clang] [compiler-rt] [libcxxabi] [llvm] Automatic removal of unused standard header (PR #192800)

Andrey Ali Khan Bolshakov via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 23 05:22:57 PDT 2026


bolshakov-a wrote:

Note that diskarzhan and iwyu are indeed incompatible. When IWYU encounters e.g. `str1 == str2`, it should report `<string>` because it cannot assume that `std::string` was explicitly spelled at `str1` or `str2` declarations, nor that `#include <string>` appeared somewhere before them (maybe, `<stacktrace>` provides `std::string` definition but doesn't provide `operator==` for it; see https://discourse.llvm.org/t/should-stacktrace-provide-string/89605), and I don't know which standard library classes can be excluded from such a precautionary measure.

There are some more cases when a standard library header is required even when the type is not explicitly written:
```cpp
// Requires '#include <initializer_list>' despite std::initializer_list is not explicitly spelled.
for (int i : {1,2,3})
  do_smth_with(i);
// Requires '#include <typeinfo>' despite std::type_info is not explicitly spelled.
const auto& ti = typeid(int);
```
That said, iwyu and diskarzhan implement different approaches: while iwyu exposes some more paranoid behavior, diskarzhan requires a header only when some symbol from it is explicitly written and thus provides a reasonable approximation for most use cases.

https://github.com/llvm/llvm-project/pull/192800


More information about the libcxx-commits mailing list