diff options
author | Sam McCall <sam.mccall@gmail.com> | 2022-02-26 14:08:12 +0100 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2022-02-26 14:11:48 +0100 |
commit | e63d7bdc28e42b537ba29708e7db9f5d1dedefc0 (patch) | |
tree | 7c98b47fde4b00d414f53b8d3413aef399c86dbc | |
parent | 6c72a97c0e2d9dd884d67315629be1c219da3b34 (diff) | |
download | llvm-e63d7bdc28e42b537ba29708e7db9f5d1dedefc0.zip llvm-e63d7bdc28e42b537ba29708e7db9f5d1dedefc0.tar.gz llvm-e63d7bdc28e42b537ba29708e7db9f5d1dedefc0.tar.bz2 |
[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
-rw-r--r-- | clang-tools-extra/clangd/IncludeCleaner.cpp | 6 | ||||
-rw-r--r-- | clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp | 16 |
2 files changed, 17 insertions, 5 deletions
diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp index cb50804..90dfb2b 100644 --- a/clang-tools-extra/clangd/IncludeCleaner.cpp +++ b/clang-tools-extra/clangd/IncludeCleaner.cpp @@ -73,10 +73,8 @@ public: } 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 65942fe..b6bf769 100644 --- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp +++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp @@ -86,6 +86,19 @@ TEST(IncludeCleaner, ReferencedLocations) { "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; |