Skip to content

Commit a7e8d6c

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

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
@@ -6133,6 +6133,7 @@ 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+
61366137
if (const auto *T = Fn->getType().getTypePtr()->getAs<TypedefType>()) {
61376138
Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
61386139

@@ -6141,6 +6142,11 @@ static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) {
61416142
if (const auto *const VD = dyn_cast<VarDecl>(D)) {
61426143
Target = VD->getTypeSourceInfo()->getTypeLoc();
61436144
}
6145+
} else if (const auto *ME = dyn_cast<MemberExpr>(Fn)) {
6146+
const auto *MD = ME->getMemberDecl();
6147+
if (const auto *FD = dyn_cast<FieldDecl>(MD)) {
6148+
Target = FD->getTypeSourceInfo()->getTypeLoc();
6149+
}
61446150
}
61456151

61466152
if (!Target)

0 commit comments

Comments
 (0)