diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp index 766998eb4f3c7..bd88a0912b537 100644 --- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -1462,6 +1462,23 @@ TEST(SignatureHelpTest, FunctionPointers) { typedef void (__stdcall *fn)(int x, int y); fn foo; int main() { foo(^); } + )cpp", + // Field of function pointer type + R"cpp( + struct S { + void (*foo)(int x, int y); + }; + S s; + int main() { s.foo(^); } + )cpp", + // Field of function pointer typedef type + R"cpp( + typedef void (*fn)(int x, int y); + struct S { + fn foo; + }; + S s; + int main() { s.foo(^); } )cpp"}; for (auto Test : Tests) EXPECT_THAT(signatures(Test).signatures, diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index adb82d3f6d176..c4c169da78f25 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -6133,6 +6133,7 @@ ProduceSignatureHelp(Sema &SemaRef, MutableArrayRef Candidates, // so that we can recover argument names from it. static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) { TypeLoc Target; + if (const auto *T = Fn->getType().getTypePtr()->getAs()) { Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc(); @@ -6141,6 +6142,11 @@ static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn) { if (const auto *const VD = dyn_cast(D)) { Target = VD->getTypeSourceInfo()->getTypeLoc(); } + } else if (const auto *ME = dyn_cast(Fn)) { + const auto *MD = ME->getMemberDecl(); + if (const auto *FD = dyn_cast(MD)) { + Target = FD->getTypeSourceInfo()->getTypeLoc(); + } } if (!Target)