[clang-tools-extra] [include-cleaner] don't consider the associated header unused (PR #67228)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 4 05:02:35 PDT 2023
================
@@ -276,6 +280,27 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, public CommentHandler {
KeepStack.pop_back(); // Pop immediately for single-line keep pragma.
}
+ // Consider marking H as the "associated header" of the main file.
+ //
+ // Our heuristic:
+ // - it must be the first #include in the main file
+ // - it must have the same name stem as the main file (foo.h and foo.cpp)
+ // (IWYU pragma: associated is also supported, just not by this function).
+ //
+ // We consider the associated header as if it had a keep pragma.
+ // (Unlike IWYU, we don't treat #includes inside the associated header as if
+ // they were written in the main file.)
+ void checkForDeducedAssociated(std::optional<Header> H) {
+ namespace path = llvm::sys::path;
+ if (!InMainFile || SeenAssociatedCandidate)
+ return;
+ SeenAssociatedCandidate = true;
----------------
kadircet wrote:
i think this is still worth a comment, `Make sure we don't consider anything but the first include of the main file` ?
https://github.com/llvm/llvm-project/pull/67228
More information about the cfe-commits
mailing list