[PATCH] D136212: [clangd] consider ~^foo() to target the destructor, not the type
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 18 16:43:21 PDT 2022
sammccall updated this revision to Diff 468741.
sammccall added a comment.
format
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136212/new/
https://reviews.llvm.org/D136212
Files:
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -466,7 +466,10 @@
{"struct foo { [[int has^h<:32:>]]; };", "FieldDecl"},
{"struct foo { [[op^erator int()]]; };", "CXXConversionDecl"},
{"struct foo { [[^~foo()]]; };", "CXXDestructorDecl"},
- // FIXME: The following to should be class itself instead.
+ {"struct foo { [[~^foo()]]; };", "CXXDestructorDecl"},
+ {"template <class T> struct foo { ~foo<[[^T]]>(){} };",
+ "TemplateTypeParmTypeLoc"},
+ {"struct foo {}; void bar(foo *f) { [[f->~^foo]](); }", "MemberExpr"},
{"struct foo { [[fo^o(){}]] };", "CXXConstructorDecl"},
{R"cpp(
Index: clang-tools-extra/clangd/Selection.cpp
===================================================================
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -860,7 +860,7 @@
// is not available to the node's children.
// Usually empty, but sometimes children cover tokens but shouldn't own them.
SourceRange earlySourceRange(const DynTypedNode &N) {
- if (const Decl *D = N.get<Decl>()) {
+ if (const Decl *VD = N.get<VarDecl>()) {
// We want the name in the var-decl to be claimed by the decl itself and
// not by any children. Ususally, we don't need this, because source
// ranges of children are not overlapped with their parent's.
@@ -869,8 +869,23 @@
// auto fun = [bar = foo]() { ... }
// ~~~~~~~~~ VarDecl
// ~~~ |- AutoTypeLoc
- if (const auto *DD = llvm::dyn_cast<VarDecl>(D))
- return DD->getLocation();
+ return VD->getLocation();
+ }
+
+ // When declaring a destructor ~Foo(), attribute Foo to the destructor
+ // rather than the TypeLoc nested inside it.
+ // We still traverse the TypeLoc, because it may contain other targeted
+ // things like the T in ~Foo<T>().
+ if (const auto *CDD = N.get<CXXDestructorDecl>())
+ return CDD->getNameInfo().getNamedTypeInfo()->getTypeLoc().getBeginLoc();
+ if (const Stmt *S = N.get<MemberExpr>()) {
+ if (const auto *ME = llvm::dyn_cast<MemberExpr>(S)) {
+ auto NameInfo = ME->getMemberNameInfo();
+ llvm::errs() << "name " << NameInfo.getAsString() << "\n";
+ if (NameInfo.getName().getNameKind() ==
+ DeclarationName::CXXDestructorName)
+ return NameInfo.getNamedTypeInfo()->getTypeLoc().getBeginLoc();
+ }
}
return SourceRange();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136212.468741.patch
Type: text/x-patch
Size: 2684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221018/347cf4a2/attachment.bin>
More information about the cfe-commits
mailing list