hokein updated this revision to Diff 545589. hokein marked an inline comment as done. hokein added a comment.
address review comment Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D156650/new/ https://reviews.llvm.org/D156650 Files: clang-tools-extra/clangd/IncludeCleaner.cpp clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp +++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp @@ -78,6 +78,8 @@ auto TU = TestTU::withCode(R"cpp( #include <list> #include <queue> + #include <vector> // IWYU pragma: keep + #include <string> // IWYU pragma: export std::list<int> x; )cpp"); // Layout of std library impl is not relevant. @@ -86,10 +88,13 @@ namespace std { template <typename> class list {}; template <typename> class queue {}; + template <typename> class vector {}; } )cpp"; TU.AdditionalFiles["list"] = "#include <bits>"; TU.AdditionalFiles["queue"] = "#include <bits>"; + TU.AdditionalFiles["vector"] = "#include <bits>"; + TU.AdditionalFiles["string"] = "#include <bits>"; TU.ExtraArgs = {"-isystem", testRoot()}; auto AST = TU.build(); IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST); Index: clang-tools-extra/clangd/IncludeCleaner.cpp =================================================================== --- clang-tools-extra/clangd/IncludeCleaner.cpp +++ clang-tools-extra/clangd/IncludeCleaner.cpp @@ -71,6 +71,8 @@ bool mayConsiderUnused( const Inclusion &Inc, ParsedAST &AST, const include_cleaner::PragmaIncludes *PI) { + if (PI && PI->shouldKeep(Inc.HashLine + 1)) + return false; // FIXME(kirillbobyrev): We currently do not support the umbrella headers. // System headers are likely to be standard library headers. // Until we have good support for umbrella headers, don't warn about them. @@ -82,8 +84,6 @@ AST.getIncludeStructure().getRealPath(HID)); assert(FE); if (PI) { - if (PI->shouldKeep(Inc.HashLine + 1)) - return false; // Check if main file is the public interface for a private header. If so we // shouldn't diagnose it as unused. if (auto PHeader = PI->getPublic(*FE); !PHeader.empty()) {
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp +++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp @@ -78,6 +78,8 @@ auto TU = TestTU::withCode(R"cpp( #include <list> #include <queue> + #include <vector> // IWYU pragma: keep + #include <string> // IWYU pragma: export std::list<int> x; )cpp"); // Layout of std library impl is not relevant. @@ -86,10 +88,13 @@ namespace std { template <typename> class list {}; template <typename> class queue {}; + template <typename> class vector {}; } )cpp"; TU.AdditionalFiles["list"] = "#include <bits>"; TU.AdditionalFiles["queue"] = "#include <bits>"; + TU.AdditionalFiles["vector"] = "#include <bits>"; + TU.AdditionalFiles["string"] = "#include <bits>"; TU.ExtraArgs = {"-isystem", testRoot()}; auto AST = TU.build(); IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST); Index: clang-tools-extra/clangd/IncludeCleaner.cpp =================================================================== --- clang-tools-extra/clangd/IncludeCleaner.cpp +++ clang-tools-extra/clangd/IncludeCleaner.cpp @@ -71,6 +71,8 @@ bool mayConsiderUnused( const Inclusion &Inc, ParsedAST &AST, const include_cleaner::PragmaIncludes *PI) { + if (PI && PI->shouldKeep(Inc.HashLine + 1)) + return false; // FIXME(kirillbobyrev): We currently do not support the umbrella headers. // System headers are likely to be standard library headers. // Until we have good support for umbrella headers, don't warn about them. @@ -82,8 +84,6 @@ AST.getIncludeStructure().getRealPath(HID)); assert(FE); if (PI) { - if (PI->shouldKeep(Inc.HashLine + 1)) - return false; // Check if main file is the public interface for a private header. If so we // shouldn't diagnose it as unused. if (auto PHeader = PI->getPublic(*FE); !PHeader.empty()) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits