Skip to content

Commit 258c048

Browse files
authored
[clang][bytecode] Fix copy constructors for empty unions (#147050)
Nothing to do in that case.
1 parent 45909ec commit 258c048

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5836,6 +5836,8 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
58365836
return false;
58375837

58385838
if (R->isUnion() && Ctor->isCopyOrMoveConstructor()) {
5839+
if (R->getNumFields() == 0)
5840+
return this->emitRetVoid(Ctor);
58395841
// union copy and move ctors are special.
58405842
assert(cast<CompoundStmt>(Ctor->getBody())->body_empty());
58415843
if (!this->emitThis(Ctor))

clang/test/AST/ByteCode/unions.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,18 @@ namespace MoveOrAssignOp {
600600
}
601601
static_assert(foo());
602602
}
603+
604+
namespace CopyEmptyUnion {
605+
struct A {
606+
union {}; // both-warning {{declaration does not declare anything}}
607+
};
608+
constexpr int foo() {
609+
A a;
610+
A a2 = a;
611+
return 1;
612+
}
613+
static_assert(foo() == 1);
614+
}
603615
#endif
604616

605617
namespace AddressComparison {

0 commit comments

Comments
 (0)