[clang-tools-extra] [clangd] Place lambda return type hints after exception specifications (PR #219829)

via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 30 10:33:18 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: Machillka (Machillka)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/219829.diff


2 Files Affected:

- (modified) clang-tools-extra/clangd/InlayHints.cpp (+1-1) 
- (modified) clang-tools-extra/clangd/unittests/InlayHintTests.cpp (+9) 


``````````diff
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.

``````````

</details>


https://github.com/llvm/llvm-project/pull/219829


More information about the cfe-commits mailing list