Skip to content

Commit a35f940

Browse files
authored
[clangd] Support operators new and delete in textDocument/references (#135620)
1 parent 3334c35 commit a35f940

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

clang-tools-extra/clangd/unittests/XRefsTests.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,15 @@ TEST(FindReferences, WithinAST) {
23032303
bool $decl[[operator]]"" _u^dl(unsigned long long value);
23042304
bool x = $(x)[[1_udl]];
23052305
)cpp",
2306-
};
2306+
R"cpp(
2307+
struct S {
2308+
public:
2309+
static void $decl(S)[[operator]] delete(void *);
2310+
static void deleteObject(S *S) {
2311+
$(S::deleteObject)[[de^lete]] S;
2312+
}
2313+
};
2314+
)cpp"};
23072315
for (const char *Test : Tests)
23082316
checkFindRefs(Test);
23092317
}

clang/lib/Index/IndexBody.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
153153
ParentDC);
154154
}
155155

156+
bool VisitCXXNewExpr(CXXNewExpr *E) {
157+
if (E->isGlobalNew() || !E->getOperatorNew())
158+
return true;
159+
return IndexCtx.handleReference(E->getOperatorNew(), E->getBeginLoc(),
160+
Parent, ParentDC);
161+
}
162+
163+
bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
164+
if (E->isGlobalDelete() || !E->getOperatorDelete())
165+
return true;
166+
return IndexCtx.handleReference(E->getOperatorDelete(), E->getBeginLoc(),
167+
Parent, ParentDC);
168+
}
169+
156170
bool VisitLabelStmt(LabelStmt *S) {
157171
if (IndexCtx.shouldIndexFunctionLocalSymbols())
158172
return IndexCtx.handleDecl(S->getDecl());

0 commit comments

Comments
 (0)