[PATCH] D136216: [clangd] go-to-def on new/delete targets the constructor
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 18 18:11:34 PDT 2022
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
Related to https://github.com/clangd/clangd/issues/1321
(but does not actually change the behavior of find-refs)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D136216
Files:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/HeuristicResolver.h
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -756,11 +756,12 @@
Code = R"cpp(
struct X {
+ X();
static void *operator new(unsigned long);
};
auto* k = [[new]] X();
)cpp";
- EXPECT_DECLS("CXXNewExpr", "static void *operator new(unsigned long)");
+ EXPECT_DECLS("CXXNewExpr", "static void *operator new(unsigned long)", "X()");
Code = R"cpp(
void *operator new(unsigned long);
auto* k = [[new]] int();
@@ -769,13 +770,15 @@
Code = R"cpp(
struct X {
+ ~X();
static void operator delete(void *) noexcept;
};
void k(X* x) {
[[delete]] x;
}
)cpp";
- EXPECT_DECLS("CXXDeleteExpr", "static void operator delete(void *) noexcept");
+ EXPECT_DECLS("CXXDeleteExpr", "static void operator delete(void *) noexcept",
+ "~X() noexcept");
Code = R"cpp(
void operator delete(void *) noexcept;
void k(int* x) {
Index: clang-tools-extra/clangd/HeuristicResolver.h
===================================================================
--- clang-tools-extra/clangd/HeuristicResolver.h
+++ clang-tools-extra/clangd/HeuristicResolver.h
@@ -17,6 +17,7 @@
class ASTContext;
class CallExpr;
class CXXDependentScopeMemberExpr;
+class CXXDestructorDecl;
class DeclarationName;
class DependentScopeDeclRefExpr;
class NamedDecl;
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -281,9 +281,32 @@
void VisitSizeOfPackExpr(const SizeOfPackExpr *SE) {
Outer.add(SE->getPack(), Flags);
}
+ void VisitCXXNewExpr(const CXXNewExpr *CNE) {
+ Outer.add(CNE->getOperatorNew(), Flags);
+ // Also consider `new` a reference to any constructor that is called.
+ if (auto *CCE = CNE->getConstructExpr())
+ Outer.add(CCE, Flags);
+ // FIXME: heuristically resolve constructors in dependent code.
+ }
+ void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE) {
+ Outer.add(CDE->getOperatorDelete(), Flags);
+ // Also consider `delete` a reference to any destructor that is called.
+ QualType T = CDE->getDestroyedType();
+ if (T.isNull())
+ return;
+ if (const auto *CRD = T->getAsCXXRecordDecl()) {
+ if (auto *CDD = CRD->getDestructor())
+ Outer.add(CDD, Flags);
+ }
+ // FIXME: heuristically resolve destructors in dependent code.
+ }
void VisitCXXConstructExpr(const CXXConstructExpr *CCE) {
Outer.add(CCE->getConstructor(), Flags);
}
+ void
+ VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *CCE) {
+ // FIXME: heuristically resolve constructors in dependent code.
+ }
void VisitDesignatedInitExpr(const DesignatedInitExpr *DIE) {
for (const DesignatedInitExpr::Designator &D :
llvm::reverse(DIE->designators()))
@@ -341,12 +364,6 @@
void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
Outer.add(POE->getSyntacticForm(), Flags);
}
- void VisitCXXNewExpr(const CXXNewExpr *CNE) {
- Outer.add(CNE->getOperatorNew(), Flags);
- }
- void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE) {
- Outer.add(CDE->getOperatorDelete(), Flags);
- }
};
Visitor(*this, Flags).Visit(S);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136216.468755.patch
Type: text/x-patch
Size: 3639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221019/4f7c0a5d/attachment.bin>
More information about the cfe-commits
mailing list