llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> Nothing to do in that case. --- Full diff: https://github.com/llvm/llvm-project/pull/147050.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2) - (modified) clang/test/AST/ByteCode/unions.cpp (+12) ``````````diff 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 { `````````` </details> https://github.com/llvm/llvm-project/pull/147050 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits