(spin off from [NFC] Add explicit #include abi-breaking.h where its macros are used. by dfukalov · Pull Request #109453 · llvm/llvm-project · GitHub conversation with @mehdi_amini @dfukalov )
I think we’ve generally seen/accepted well-formed Include-What-You-Use changes historically, but the letter of the style guide suggests indirect inclusion is acceptable.
I think it’s “not a big deal, but would be better if the inclusions were explicit, rather than implicit” - I’m not likely to check someone’s #includes carefully to ensure they include everything they need explicitly, but I’m happy to accept patches that add such explicit inclusions to reduce spooky-action-at-a-distance maintenance issues.
(by maintenance issues I mean: Removing a header that is no longer explicitly used can break the build because something that header includes is implicitly used. Equally, removing the include from a header when it’s no longer needed in that header can break the build because someone including that header was relying on the indirect inclusion.
In the case of #ifdef and #if macros, these cases can become non-breaking silent behavior changes (-Wundef will catch the #if cases, but not the #ifdef cases))
Adding these missing includes doesn’t substantially impact compile time since compilers have fast-paths through re-included files with the usual macro-based header repetaed inclusion protetion.
So I’d propose just removing the “or indirectly” portion of the phrase " You must include all of the header files that you are using — you can include them either directly or indirectly through another header file." in LLVM Coding Standards — LLVM 20.0.0git documentation unless anyone has objections.
This wording would still not be entirely precise - I don’t think it’s necessary to include things that you indirectly depend on that are part of interfaces you include (if you include some header that defines a base class with, for instance, an abstract function that takes some type T and your derivted class implements that function and so depends on T - the implicit dependency via the base class header seems generally OK to me? Though I think everyone’s got some judgement on those sort of dependencies - I’m not sure how useful it is to make a really precise enumeration for these sort of cases… but open to other folks feeling differently) - I guess the Google style guide says even that closely connected indirect inclusion shouldn’t be used ( Google C++ Style Guide ) - so I’m open to that too.
Practically speaking, I think the change in policy wouldn’t affect things day-to-day, but allow this sort of cleanup to be done whenever someone felt the itch to make such changes, and in doing so would reduce the maintenance burden of the codebase for those removing unused inclusions based on human or automated local reasoning.