diff --git a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp --- a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp +++ b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp @@ -248,6 +248,10 @@ // Add name match hints to deduplicated providers. llvm::StringRef SymbolName = symbolName(S); for (auto &H : Headers) { + // Don't apply name match hints to standard headers as the standard headers + // are already ranked in the stdlib mapping. + if (H.kind() == Header::Standard) + continue; if (nameMatch(SymbolName, H)) H.Hint |= Hints::PreferredHeader; } diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp --- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp @@ -486,5 +486,16 @@ } } +TEST_F(HeadersForSymbolTest, StandardHeaders) { + Inputs.Code = "void assert();"; + buildAST(); + EXPECT_THAT( + headersFor("assert"), + // Respect the ordering from the stdlib mapping. + UnorderedElementsAre(tooling::stdlib::Header::named(""), + tooling::stdlib::Header::named(""))); +} + + } // namespace } // namespace clang::include_cleaner