[PATCH] D72638: [clangd] Fix rename for explicit destructor calls
Kirill Bobyrev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 16 10:22:43 PST 2020
kbobyrev updated this revision to Diff 238541.
kbobyrev added a comment.
Avoid duplicate references by filtering out destructor calls
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72638/new/
https://reviews.llvm.org/D72638
Files:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ 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 {};
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ 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 {};
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ 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<CXXDestructorDecl>(E->getMemberDecl()))
+ return;
Refs.push_back(ReferenceLoc{E->getQualifierLoc(),
E->getMemberNameInfo().getLoc(),
/*IsDecl=*/false,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72638.238541.patch
Type: text/x-patch
Size: 3103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200116/679baa6d/attachment.bin>
More information about the cfe-commits
mailing list