File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -626,10 +626,15 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
626626
627627 bool VisitLambdaExpr (LambdaExpr *E) {
628628 FunctionDecl *D = E->getCallOperator ();
629- if (!E->hasExplicitResultType ())
630- addReturnTypeHint (D, E->hasExplicitParameters ()
631- ? D->getFunctionTypeLoc ().getRParenLoc ()
632- : E->getIntroducerRange ().getEnd ());
629+ if (!E->hasExplicitResultType ()) {
630+ SourceLocation TypeHintLoc;
631+ if (!E->hasExplicitParameters ())
632+ TypeHintLoc = E->getIntroducerRange ().getEnd ();
633+ else if (auto FTL = D->getFunctionTypeLoc ())
634+ TypeHintLoc = FTL.getRParenLoc ();
635+ if (TypeHintLoc.isValid ())
636+ addReturnTypeHint (D, TypeHintLoc);
637+ }
633638 return true ;
634639 }
635640
Original file line number Diff line number Diff line change @@ -1576,6 +1576,22 @@ TEST(TypeHints, Aliased) {
15761576 EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type), IsEmpty ());
15771577}
15781578
1579+ TEST (TypeHints, CallingConvention) {
1580+ // Check that we don't crash for lambdas without a FunctionTypeLoc
1581+ // https://github.com/clangd/clangd/issues/2223
1582+ std::string Code = R"cpp(
1583+ void test() {
1584+ []() __cdecl {};
1585+ }
1586+ )cpp" ;
1587+ TestTU TU = TestTU::withCode (Code);
1588+ TU.ExtraArgs .push_back (" --target=x86_64-w64-mingw32" );
1589+ TU.PredefineMacros = true ; // for the __cdecl
1590+ auto AST = TU.build ();
1591+
1592+ EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type), IsEmpty ());
1593+ }
1594+
15791595TEST (TypeHints, Decltype) {
15801596 assertTypeHints (R"cpp(
15811597 $a[[decltype(0)]] a;
You can’t perform that action at this time.
0 commit comments