Skip to content

Commit 10dc3a8

Browse files
committed
[clang][Interp] Fix empty InitListExprs for unions
We still need to handle Inits.size() == 0, but we can do that earlier.
1 parent f81da75 commit 10dc3a8

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,9 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
10531053
if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
10541054
return this->visitInitializer(Inits[0]);
10551055

1056+
if (Inits.size() == 0)
1057+
return this->emitFinishInit(E);
1058+
10561059
auto initPrimitiveField = [=](const Record::Field *FieldToInit,
10571060
const Expr *Init, PrimType T) -> bool {
10581061
if (!this->visit(Init))

clang/test/AST/Interp/unions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,10 @@ namespace SimpleStore {
4242
return a.b;
4343
}
4444
static_assert(foo() == 10, "");
45+
46+
constexpr int empty() {
47+
A a{}; /// Just test that this works.
48+
return 10;
49+
}
50+
static_assert(empty() == 10, "");
4551
}

0 commit comments

Comments
 (0)