https://github.com/Machillka created https://github.com/llvm/llvm-project/pull/219829
Lambda return type hints are currently anchored to the closing parenthesis. This causes a noexcept lambda to be displayed as if its trailing return type came before the exception specification. Use the end of the function type's local source range instead, which is where a trailing return type would be written. Fixes clangd/clangd#2696 Added a regression test for noexcept lambdas. >From 95e7332d5fe798f358b13c396240f38b16cd48f3 Mon Sep 17 00:00:00 2001 From: Machillka <[email protected]> Date: Mon, 31 Aug 2026 01:28:34 +0800 Subject: [PATCH] [clangd] Place lambda return type hints after exception specifications Lambda return type hints are currently anchored to the closing parenthesis. This causes a noexcept lambda to be displayed as if its trailing return type came before the exception specification. Use the end of the function type's local source range instead, which is where a trailing return type would be written. Fixes clangd/clangd#2696 --- clang-tools-extra/clangd/InlayHints.cpp | 2 +- clang-tools-extra/clangd/unittests/InlayHintTests.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp index 5bae4cc040210..1a49bc297dba2 100644 --- a/clang-tools-extra/clangd/InlayHints.cpp +++ b/clang-tools-extra/clangd/InlayHints.cpp @@ -604,7 +604,7 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> { if (!E->hasExplicitParameters()) TypeHintLoc = E->getIntroducerRange().getEnd(); else if (auto FTL = D->getFunctionTypeLoc()) - TypeHintLoc = FTL.getRParenLoc(); + TypeHintLoc = FTL.getLocalRangeEnd(); if (TypeHintLoc.isValid()) addReturnTypeHint(D, TypeHintLoc); } diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp index b90f44d102018..33413a576fa74 100644 --- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp +++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp @@ -1318,6 +1318,15 @@ TEST(TypeHints, Lambda) { assertTypeHints("auto $L[[x]] = <:$ret[[:>]]{return 42;};", ExpectedHint{": (lambda)", "L"}, ExpectedHint{"-> int", "ret"}); + + // The return type follows the noexcept specifier in a lambda declarator. + // https://github.com/clangd/clangd/issues/2696 + assertTypeHints(R"cpp( + void f() { + []() $ret[[noexcept]] {}; + } + )cpp", + ExpectedHint{"-> void", "ret"}); } // Structured bindings tests. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
