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

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 1 07:01:37 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:

Hmm, ideally if we’re already emitting one diagnostic that we can’t deduce the return type, there is no need to emit a second diagnostic as well; can you see if there’s an easy way to avoid emitting ‘void lambda should not return a value’ if we’re already emitting ‘cannot deduce lambda return type from initializer list’?

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


More information about the cfe-commits mailing list