[clang] Fix crash and improve diagnostics for void lambda returns (PR #188904)

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 1 16:01:16 PDT 2026


================
@@ -18,7 +18,8 @@ void infer_void_return_type(int i) {
     switch (x) {
     case 0: return get<void>();
     case 1: return;
-    case 2: return { 1, 2.0 }; // expected-error {{cannot deduce lambda return type from initializer list}}
+    case 2: return { 1, 2.0 }; // expected-error {{cannot deduce lambda return type from initializer list}} \
+                                   // cxx11-error {{void lambda should not return a value}}
----------------
Sirraide wrote:

> > @Ko496-glitch Ah, found it, we end up in the `else if (CurCap->HasImplicitReturnType)` branch; in there, we should probably set `RetValExpr = nullptr` after issuing the `err_lambda_return_init_list` diagnostic; for some reason we don’t do that there...
> 
> how did you find this ?

I was just stepping through `ActOnCapScopeReturnStmt()` in a debugger to see what the return type would be when we get to the code that this pr modifies; that’s when I noticed that we’re emitting an error there w/o setting `RetValExpr` to null

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


More information about the cfe-commits mailing list