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 @@ -70,6 +70,8 @@ bool isIgnored(llvm::StringRef HeaderPath, HeaderFilter IgnoreHeaders) {
7070bool mayConsiderUnused (
7171 const Inclusion &Inc, ParsedAST &AST,
7272 const include_cleaner::PragmaIncludes *PI) {
73+ if (PI && PI->shouldKeep (Inc.HashLine + 1 ))
74+ return false ;
7375 // FIXME(kirillbobyrev): We currently do not support the umbrella headers.
7476 // System headers are likely to be standard library headers.
7577 // Until we have good support for umbrella headers, don't warn about them.
@@ -81,8 +83,6 @@ bool mayConsiderUnused(
8183 AST.getIncludeStructure ().getRealPath (HID));
8284 assert (FE);
8385 if (PI) {
84- if (PI->shouldKeep (Inc.HashLine + 1 ))
85- return false ;
8686 // Check if main file is the public interface for a private header. If so we
8787 // shouldn't diagnose it as unused.
8888 if (auto PHeader = PI->getPublic (*FE); !PHeader.empty ()) {
Original file line number Diff line number Diff line change @@ -76,6 +76,8 @@ TEST(IncludeCleaner, StdlibUnused) {
7676 auto TU = TestTU::withCode (R"cpp(
7777 #include <list>
7878 #include <queue>
79+ #include <vector> // IWYU pragma: keep
80+ #include <string> // IWYU pragma: export
7981 std::list<int> x;
8082 )cpp" );
8183 // Layout of std library impl is not relevant.
@@ -84,10 +86,13 @@ TEST(IncludeCleaner, StdlibUnused) {
8486 namespace std {
8587 template <typename> class list {};
8688 template <typename> class queue {};
89+ template <typename> class vector {};
8790 }
8891 )cpp" ;
8992 TU.AdditionalFiles [" list" ] = " #include <bits>" ;
9093 TU.AdditionalFiles [" queue" ] = " #include <bits>" ;
94+ TU.AdditionalFiles [" vector" ] = " #include <bits>" ;
95+ TU.AdditionalFiles [" string" ] = " #include <bits>" ;
9196 TU.ExtraArgs = {" -isystem" , testRoot ()};
9297 auto AST = TU.build ();
9398 IncludeCleanerFindings Findings = computeIncludeCleanerFindings (AST);
You can’t perform that action at this time.
0 commit comments