[clangd] Handle MemberPointerTypeLoc in SelectionTree (#183242)

This is another type loc that overlaps the name of the declaration whose
type it is, and so needs special handling to allow the declaration
itself to be targeted.

Fixes https://github.com/clangd/clangd/issues/2608
This commit is contained in:
Nathan Ridge 2026-02-25 01:09:40 -05:00 committed by GitHub
parent bc9d5b01d3
commit 0fa0bb1067
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -959,6 +959,10 @@ private:
claimRange(PTL.getStarLoc(), Result);
return;
}
if (auto MPTL = TL->getAs<MemberPointerTypeLoc>()) {
claimRange(MPTL.getLocalSourceRange(), Result);
return;
}
if (auto FTL = TL->getAs<FunctionTypeLoc>()) {
claimRange(SourceRange(FTL.getLParenLoc(), FTL.getEndLoc()), Result);
return;

View File

@ -2370,6 +2370,16 @@ TEST(FindReferences, WithinAST) {
[$(Bar)[[F^oo]]...$(Bar)[[Fo^o]] + 1] = 0,
[$(Bar)[[^Foo]] + 2] = 1
};
)cpp",
// Field of pointer-to-member type
R"cpp(
struct S { void foo(); };
struct A {
void (S::*$def(A)[[fi^eld]])();
};
void bar(A& a, S& s) {
(s.*(a.$(bar)[[field]]))();
}
)cpp"};
for (const char *Test : Tests)
checkFindRefs(Test);