Skip to content

Commit 7bad74e

Browse files
authored
[clangd] Show argument names for function pointer struct fields (#69011)
Show argument names in signature help when calling a function pointer struct field.
1 parent b930b14 commit 7bad74e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,23 @@ TEST(SignatureHelpTest, FunctionPointers) {
14621462
typedef void (__stdcall *fn)(int x, int y);
14631463
fn foo;
14641464
int main() { foo(^); }
1465+
)cpp",
1466+
// Field of function pointer type
1467+
R"cpp(
1468+
struct S {
1469+
void (*foo)(int x, int y);
1470+
};
1471+
S s;
1472+
int main() { s.foo(^); }
1473+
)cpp",
1474+
// Field of function pointer typedef type
1475+
R"cpp(
1476+
typedef void (*fn)(int x, int y);
1477+
struct S {
1478+
fn foo;
1479+
};
1480+
S s;
1481+
int main() { s.foo(^); }
14651482
)cpp"};
14661483
for (auto Test : Tests)
14671484
EXPECT_THAT(signatures(Test).signatures,

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6137,6 +6137,7 @@ ProduceSignatureHelp(Sema &SemaRef, MutableArrayRef<ResultCandidate> Candidates,
61376137
// so that we can recover argument names from it.
61386138
static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
61396139
TypeLoc Target;
6140+
61406141
if (const auto *T = Fn->getType().getTypePtr()->getAs<TypedefType>()) {
61416142
Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
61426143

@@ -6145,6 +6146,11 @@ static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
61456146
if (const auto *const VD = dyn_cast<VarDecl>(D)) {
61466147
Target = VD->getTypeSourceInfo()->getTypeLoc();
61476148
}
6149+
} else if (const auto *ME = dyn_cast<MemberExpr>(Fn)) {
6150+
const auto *MD = ME->getMemberDecl();
6151+
if (const auto *FD = dyn_cast<FieldDecl>(MD)) {
6152+
Target = FD->getTypeSourceInfo()->getTypeLoc();
6153+
}
61486154
}
61496155

61506156
if (!Target)

0 commit comments

Comments
 (0)