aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2022-02-26 14:08:12 +0100
committerSam McCall <sam.mccall@gmail.com>2022-02-26 14:11:48 +0100
commite63d7bdc28e42b537ba29708e7db9f5d1dedefc0 (patch)
tree7c98b47fde4b00d414f53b8d3413aef399c86dbc
parent6c72a97c0e2d9dd884d67315629be1c219da3b34 (diff)
downloadllvm-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.cpp6
-rw-r--r--clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp16
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;