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> {
626
626
627
627
bool VisitLambdaExpr (LambdaExpr *E) {
628
628
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
+ }
633
638
return true ;
634
639
}
635
640
Original file line number Diff line number Diff line change @@ -1576,6 +1576,22 @@ TEST(TypeHints, Aliased) {
1576
1576
EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type), IsEmpty ());
1577
1577
}
1578
1578
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
+
1579
1595
TEST (TypeHints, Decltype) {
1580
1596
assertTypeHints (R"cpp(
1581
1597
$a[[decltype(0)]] a;
You can’t perform that action at this time.
0 commit comments