diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp --- a/clang-tools-extra/clangd/IncludeCleaner.cpp +++ b/clang-tools-extra/clangd/IncludeCleaner.cpp @@ -74,7 +74,8 @@ // System headers are likely to be standard library headers. // Until we have good support for umbrella headers, don't warn about them. if (Inc.Written.front() == '<') - return tooling::stdlib::Header::named(Inc.Written).has_value(); + return tooling::stdlib::Header::named(Inc.Written).has_value() && + !(PI && PI->shouldKeep(Inc.HashLine + 1)); assert(Inc.HeaderID); auto HID = static_cast(*Inc.HeaderID); auto FE = AST.getSourceManager().getFileManager().getFileRef( diff --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp --- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp +++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp @@ -76,6 +76,8 @@ auto TU = TestTU::withCode(R"cpp( #include #include + #include // IWYU pragma: keep + #include // IWYU pragma: export std::list x; )cpp"); // Layout of std library impl is not relevant. @@ -84,10 +86,13 @@ namespace std { template class list {}; template class queue {}; + template class vector {}; } )cpp"; TU.AdditionalFiles["list"] = "#include "; TU.AdditionalFiles["queue"] = "#include "; + TU.AdditionalFiles["vector"] = "#include "; + TU.AdditionalFiles["string"] = "#include "; TU.ExtraArgs = {"-isystem", testRoot()}; auto AST = TU.build(); IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);