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

Kartik Ohlan via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 1 15:57:34 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}}
----------------
Ko496-glitch wrote:

i was gonna say i just ran lldb and The primary diagnostic ("cannot deduce…") is emitted within ActOnReturnStmt via DeduceFunctionTypeFromReturnExpr, but we don’t bail out with a StmtError. Instead, control flow continues into Sema::ActOnFinishFunctionBody, where the fallback logic treats the return type as void and emits the redundant "void lambda should not return a value" diagnostic. This looks like we’re missing an early exit after deduction failure.

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


More information about the cfe-commits mailing list