diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -661,7 +661,9 @@ } bool VisitCXXMemberCallExpr(CXXMemberCallExpr *CE) { - if (isa(CE->getMethodDecl())) { + // getMethodDecl can return nullptr with member pointers, e.g. + // `(foo.*pointer_to_member_fun)(arg);` + if (isa_and_present(CE->getMethodDecl())) { if (auto *ME = dyn_cast(CE->getCallee())) { if (auto *TI = ME->getMemberNameInfo().getNamedTypeInfo()) { H.addExtraModifier(TI->getTypeLoc().getBeginLoc(), diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -887,6 +887,17 @@ $TemplateParameter[[T]] $Variable_def[[x]] = {}; template <> int $Variable_def[[x]] = (int)sizeof($Class[[Base]]); + )cpp", + // no crash + R"cpp( + struct $Class_def[[Foo]] { + void $Method_decl[[foo]](); + }; + + void $Function_def[[s]]($Class[[Foo]] $Parameter_def[[f]]) { + auto $LocalVariable_def[[k]] = &$Class[[Foo]]::$Method[[foo]]; + ($Parameter[[f]].*$LocalVariable[[k]])(); // no crash on VisitCXXMemberCallExpr + } )cpp"}; for (const auto &TestCase : TestCases) // Mask off scope modifiers to keep the tests manageable.