File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ bool isIgnored(llvm::StringRef HeaderPath, HeaderFilter IgnoreHeaders) {
7171bool mayConsiderUnused (
7272 const Inclusion &Inc, ParsedAST &AST,
7373 const include_cleaner::PragmaIncludes *PI) {
74+ if (PI && PI->shouldKeep (Inc.HashLine + 1 ))
75+ return false ;
7476 // FIXME(kirillbobyrev): We currently do not support the umbrella headers.
7577 // System headers are likely to be standard library headers.
7678 // Until we have good support for umbrella headers, don't warn about them.
@@ -82,8 +84,6 @@ bool mayConsiderUnused(
8284 AST.getIncludeStructure ().getRealPath (HID));
8385 assert (FE);
8486 if (PI) {
85- if (PI->shouldKeep (Inc.HashLine + 1 ))
86- return false ;
8787 // Check if main file is the public interface for a private header. If so we
8888 // shouldn't diagnose it as unused.
8989 if (auto PHeader = PI->getPublic (*FE); !PHeader.empty ()) {
Original file line number Diff line number Diff line change @@ -78,6 +78,8 @@ TEST(IncludeCleaner, StdlibUnused) {
7878 auto TU = TestTU::withCode (R"cpp(
7979 #include <list>
8080 #include <queue>
81+ #include <vector> // IWYU pragma: keep
82+ #include <string> // IWYU pragma: export
8183 std::list<int> x;
8284 )cpp" );
8385 // Layout of std library impl is not relevant.
@@ -86,10 +88,13 @@ TEST(IncludeCleaner, StdlibUnused) {
8688 namespace std {
8789 template <typename> class list {};
8890 template <typename> class queue {};
91+ template <typename> class vector {};
8992 }
9093 )cpp" ;
9194 TU.AdditionalFiles [" list" ] = " #include <bits>" ;
9295 TU.AdditionalFiles [" queue" ] = " #include <bits>" ;
96+ TU.AdditionalFiles [" vector" ] = " #include <bits>" ;
97+ TU.AdditionalFiles [" string" ] = " #include <bits>" ;
9398 TU.ExtraArgs = {" -isystem" , testRoot ()};
9499 auto AST = TU.build ();
95100 IncludeCleanerFindings Findings = computeIncludeCleanerFindings (AST);
You can’t perform that action at this time.
0 commit comments