https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/233189

Since we always call `toRValue()` here, all the fields we read need to be 
initialized.

Fixes https://github.com/llvm/llvm-project/issues/232904

>From 2aa4e56444774283098f5d8daa2c96ce56ad28d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Sun, 18 Oct 2026 07:19:04 +0200
Subject: [PATCH] [clang][bytecode] Always check for initialization in RetValue

---
 clang/lib/AST/ByteCode/EvalEmitter.cpp |  2 +-
 clang/test/AST/ByteCode/cxx2a.cpp      | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp 
b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 72ed8ad1f7a836..bfc01a3b0e9776 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -331,7 +331,7 @@ bool EvalEmitter::emitRetValue(SourceInfo Info) {
 
   if (!EvalResult.checkDynamicAllocations(S, Ptr, Info))
     return false;
-  if (CheckFullyInitialized && !EvalResult.checkFullyInitialized(S, Ptr))
+  if (!EvalResult.checkFullyInitialized(S, Ptr))
     return false;
   if (!EvalResult.checkLValueFields(S, Ptr, Info, ConstexprKind))
     return false;
diff --git a/clang/test/AST/ByteCode/cxx2a.cpp 
b/clang/test/AST/ByteCode/cxx2a.cpp
index 9fc434708b8bf2..92b82389ee81ee 100644
--- a/clang/test/AST/ByteCode/cxx2a.cpp
+++ b/clang/test/AST/ByteCode/cxx2a.cpp
@@ -331,3 +331,18 @@ namespace UnionNoActivate {
   }
   static_assert(g()); // both-error {{constant expression}} both-note {{in 
call}}
 }
+
+namespace UninitializedMemberFromConsteval {
+  struct A {
+    int x; // both-note {{subobject declared here}}
+    consteval A() { x = 4; }
+    consteval A(const A &) {}
+  };
+  void f() {
+    auto b = [] { // both-error {{call to immediate function}} \
+                  // both-note {{subobject 'x' is not initialized}}
+      auto z = [a = A()] {};
+      return z;
+    }();
+  }
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to