Author: Sam McCall Date: 2022-02-26T14:11:48+01:00 New Revision: e63d7bdc28e42b537ba29708e7db9f5d1dedefc0
URL: https://github.com/llvm/llvm-project/commit/e63d7bdc28e42b537ba29708e7db9f5d1dedefc0 DIFF: https://github.com/llvm/llvm-project/commit/e63d7bdc28e42b537ba29708e7db9f5d1dedefc0.diff LOG: [clangd] Fix include-cleaner false-positive bug For TemplateSpecializationType, we were checking the node's newness twice, so it always failed the second test. Fixes https://github.com/clangd/clangd/issues/1036 Added: Modified: clang-tools-extra/clangd/IncludeCleaner.cpp clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp index cb50804585082..90dfb2b4a3501 100644 --- a/clang-tools-extra/clangd/IncludeCleaner.cpp +++ b/clang-tools-extra/clangd/IncludeCleaner.cpp @@ -73,10 +73,8 @@ class ReferencedLocationCrawler } bool VisitTemplateSpecializationType(TemplateSpecializationType *TST) { - if (isNew(TST)) { - add(TST->getTemplateName().getAsTemplateDecl()); // Primary template. - add(TST->getAsCXXRecordDecl()); // Specialization - } + add(TST->getTemplateName().getAsTemplateDecl()); // Primary template. + add(TST->getAsCXXRecordDecl()); // Specialization return true; } diff --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp index 65942fe29c72c..b6bf7695f8873 100644 --- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp +++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp @@ -85,6 +85,19 @@ TEST(IncludeCleaner, ReferencedLocations) { "typedef bool ^Y; template <typename T> struct ^X {};", "X<Y> x;", }, + { + // https://github.com/clangd/clangd/issues/1036 + R"cpp( + struct ^Base { void ^base(); }; + template <int> struct ^Derived : Base {}; + )cpp", + R"cpp( + class Holder { + void foo() { Member.base(); } + Derived<0> Member; + }; + )cpp", + }, { "struct Foo; struct ^Foo{}; typedef Foo ^Bar;", "Bar b;", @@ -206,7 +219,8 @@ TEST(IncludeCleaner, ReferencedLocations) { { "enum class ^Color : char {};", "Color *c;", - }}; + }, + }; for (const TestCase &T : Cases) { TestTU TU; TU.Code = T.MainCode; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits