diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -596,6 +596,10 @@ } void VisitMemberExpr(const MemberExpr *E) { + // Skip destructor calls to avoid duplication: TypeLoc within will be + // visited separately. + if (llvm::dyn_cast(E->getMemberDecl())) + return; Refs.push_back(ReferenceLoc{E->getQualifierLoc(), E->getMemberNameInfo().getLoc(), /*IsDecl=*/false, diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp --- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -879,6 +879,45 @@ "8: targets = {INT2}, decl\n" "9: targets = {NS}, decl\n" "10: targets = {ns}\n"}, + // CXX Constructor, destructor and operators. + {R"cpp( + void foo() { + class $0^Bar {}; + class $1^Foo { + public: + $2^Foo() {} + ~$3^Foo() {} + + void $4^destructMe() { + this->~$5^Foo(); + $6^Foo(); + } + + $7^operator int() { return 42; } + }; + + $8^Foo $9^f; + int $10^fourtyTwo = $11^f.$12^operator int(); + $13^f.~ /*...*/ $14^Foo(); + } + )cpp", + "0: targets = {Bar}, decl\n" + "1: targets = {Foo}, decl\n" + "2: targets = {foo()::Foo::Foo}, decl\n" + // FIXME: Should this target destructor instead of the type itself + // (similar to constructor)? + "3: targets = {Foo}\n" + "4: targets = {foo()::Foo::destructMe}, decl\n" + "5: targets = {Foo}\n" + "6: targets = {Foo}\n" + "7: targets = {foo()::Foo::operator int}, decl\n" + "8: targets = {Foo}\n" + "9: targets = {f}, decl\n" + "10: targets = {fourtyTwo}, decl\n" + "11: targets = {f}\n" + "12: targets = {foo()::Foo::operator int}\n" + "13: targets = {f}\n" + "14: targets = {Foo}\n"}, // cxx constructor initializer. {R"cpp( class Base {}; diff --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp b/clang-tools-extra/clangd/unittests/RenameTests.cpp --- a/clang-tools-extra/clangd/unittests/RenameTests.cpp +++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp @@ -265,6 +265,22 @@ } )cpp", + // Destructor. + R"cpp( + class [[F^oo]] { + public: + ~[[^Foo]](); + }; + + [[Foo^]]::~[[^Foo]]() {} + + int main() { + [[Fo^o]] f; + f.~/*something*/[[^Foo]](); + f.~[[^Foo]](); + } + )cpp", + // CXXConstructor initializer list. R"cpp( class Baz {};