Skip to content

Commit 707e2b8

Browse files
authored
[clang][bytecode] Handle union move assignment operators as well (#125516)
1 parent 84ba55d commit 707e2b8

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5665,7 +5665,7 @@ bool Compiler<Emitter>::compileDestructor(const CXXDestructorDecl *Dtor) {
56655665
}
56665666

56675667
template <class Emitter>
5668-
bool Compiler<Emitter>::compileUnionCopyAssignmentOperator(
5668+
bool Compiler<Emitter>::compileUnionAssignmentOperator(
56695669
const CXXMethodDecl *MD) {
56705670
if (!this->emitThis(MD))
56715671
return false;
@@ -5693,8 +5693,9 @@ bool Compiler<Emitter>::visitFunc(const FunctionDecl *F) {
56935693
if (const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
56945694
const RecordDecl *RD = MD->getParent();
56955695

5696-
if (RD->isUnion() && MD->isCopyAssignmentOperator())
5697-
return this->compileUnionCopyAssignmentOperator(MD);
5696+
if (RD->isUnion() &&
5697+
(MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()))
5698+
return this->compileUnionAssignmentOperator(MD);
56985699

56995700
if (MD->isLambdaStaticInvoker())
57005701
return this->emitLambdaStaticInvokerBody(MD);

clang/lib/AST/ByteCode/Compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
383383
bool emitBuiltinBitCast(const CastExpr *E);
384384
bool compileConstructor(const CXXConstructorDecl *Ctor);
385385
bool compileDestructor(const CXXDestructorDecl *Dtor);
386-
bool compileUnionCopyAssignmentOperator(const CXXMethodDecl *MD);
386+
bool compileUnionAssignmentOperator(const CXXMethodDecl *MD);
387387

388388
bool checkLiteralType(const Expr *E);
389389

clang/test/AST/ByteCode/unions.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,20 @@ namespace CopyAssign {
447447
}
448448
static_assert(f2() == 12); // both-error {{not an integral constant expression}} \
449449
// both-note {{in call to}}
450+
}
451+
452+
namespace MoveAssign {
453+
union A {
454+
int a;
455+
int b;
456+
};
450457

458+
constexpr int f() {
459+
A b{13};
460+
461+
b = A{12} ;
462+
return b.a;
463+
}
464+
static_assert(f()== 12);
451465
}
452466
#endif

0 commit comments

Comments
 (0)