[clang] a35f940 - [clangd] Support operators new and delete in textDocument/references (#135620)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 22 01:42:59 PDT 2025
Author: Christian Kandeler
Date: 2025-04-22T10:42:56+02:00
New Revision: a35f940b876a09211f3e68dd25d00271b7195145
URL: https://github.com/llvm/llvm-project/commit/a35f940b876a09211f3e68dd25d00271b7195145
DIFF: https://github.com/llvm/llvm-project/commit/a35f940b876a09211f3e68dd25d00271b7195145.diff
LOG: [clangd] Support operators new and delete in textDocument/references (#135620)
Added:
Modified:
clang-tools-extra/clangd/unittests/XRefsTests.cpp
clang/lib/Index/IndexBody.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index 693e965e78a96..1892f87c8e82a 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2303,7 +2303,15 @@ TEST(FindReferences, WithinAST) {
bool $decl[[operator]]"" _u^dl(unsigned long long value);
bool x = $(x)[[1_udl]];
)cpp",
- };
+ R"cpp(
+ struct S {
+ public:
+ static void $decl(S)[[operator]] delete(void *);
+ static void deleteObject(S *S) {
+ $(S::deleteObject)[[de^lete]] S;
+ }
+ };
+ )cpp"};
for (const char *Test : Tests)
checkFindRefs(Test);
}
diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index 5e69987820730..2ed20df22bda0 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -153,6 +153,20 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
ParentDC);
}
+ bool VisitCXXNewExpr(CXXNewExpr *E) {
+ if (E->isGlobalNew() || !E->getOperatorNew())
+ return true;
+ return IndexCtx.handleReference(E->getOperatorNew(), E->getBeginLoc(),
+ Parent, ParentDC);
+ }
+
+ bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+ if (E->isGlobalDelete() || !E->getOperatorDelete())
+ return true;
+ return IndexCtx.handleReference(E->getOperatorDelete(), E->getBeginLoc(),
+ Parent, ParentDC);
+ }
+
bool VisitLabelStmt(LabelStmt *S) {
if (IndexCtx.shouldIndexFunctionLocalSymbols())
return IndexCtx.handleDecl(S->getDecl());
More information about the cfe-commits
mailing list