Skip to content

Commit 1e4b524

Browse files
committed
clangd: Show argument names for function pointer struct fields
1 parent ba79fb2 commit 1e4b524

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6133,7 +6133,17 @@ ProduceSignatureHelp(Sema &SemaRef, MutableArrayRef<ResultCandidate> Candidates,
61336133
// so that we can recover argument names from it.
61346134
static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
61356135
TypeLoc Target;
6136-
if (const auto *T = Fn->getType().getTypePtr()->getAs<TypedefType>()) {
6136+
6137+
if (const auto *ME = dyn_cast<MemberExpr>(Fn)) {
6138+
const auto *MD = ME->getMemberDecl();
6139+
if (const auto *FD = dyn_cast<FieldDecl>(MD)) {
6140+
if (const auto *T = FD->getType().getTypePtr()->getAs<TypedefType>()) {
6141+
Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
6142+
} else {
6143+
Target = FD->getTypeSourceInfo()->getTypeLoc();
6144+
}
6145+
}
6146+
} else if (const auto *T = Fn->getType().getTypePtr()->getAs<TypedefType>()) {
61376147
Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
61386148

61396149
} else if (const auto *DR = dyn_cast<DeclRefExpr>(Fn)) {

0 commit comments

Comments
 (0)