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

Nothing to do in that case.

>From bf0977ba63cee20938dccb1d39e9c53891180a18 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com>
Date: Fri, 4 Jul 2025 15:13:20 +0200
Subject: [PATCH] [clang][bytecode] Fix copy constructors for empty unions

Nothing to do in that case.
---
 clang/lib/AST/ByteCode/Compiler.cpp |  2 ++
 clang/test/AST/ByteCode/unions.cpp  | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 20580c8fe7be3..5ed65f21bb2c0 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5836,6 +5836,8 @@ bool Compiler<Emitter>::compileConstructor(const 
CXXConstructorDecl *Ctor) {
     return false;
 
   if (R->isUnion() && Ctor->isCopyOrMoveConstructor()) {
+    if (R->getNumFields() == 0)
+      return this->emitRetVoid(Ctor);
     // union copy and move ctors are special.
     assert(cast<CompoundStmt>(Ctor->getBody())->body_empty());
     if (!this->emitThis(Ctor))
diff --git a/clang/test/AST/ByteCode/unions.cpp 
b/clang/test/AST/ByteCode/unions.cpp
index 36f4b72335af3..0e5f83b9572b3 100644
--- a/clang/test/AST/ByteCode/unions.cpp
+++ b/clang/test/AST/ByteCode/unions.cpp
@@ -600,6 +600,18 @@ namespace MoveOrAssignOp {
   }
   static_assert(foo());
 }
+
+namespace CopyEmptyUnion {
+  struct A {
+    union {}; // both-warning {{declaration does not declare anything}}
+  };
+  constexpr int foo() {
+     A a;
+     A a2 = a;
+     return 1;
+  }
+  static_assert(foo() == 1);
+}
 #endif
 
 namespace AddressComparison {

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to