Skip to content

Commit

Permalink
[clang][Interp] Allow zero-init of primitives with an empty init list
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D158595
  • Loading branch information
tbaederr committed Sep 18, 2023
1 parent ce031fc commit 52a55a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,10 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {

// Primitive values.
if (std::optional<PrimType> T = classify(E->getType())) {
assert(E->getNumInits() == 1);
assert(!DiscardResult);
if (E->getNumInits() == 0)
return this->visitZeroInitializer(E->getType(), E);
assert(E->getNumInits() == 1);
return this->delegate(E->inits()[0]);
}

Expand Down
9 changes: 9 additions & 0 deletions clang/test/AST/Interp/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ static_assert(-(1 << 31), ""); // expected-error {{not an integral constant expr
// ref-error {{not an integral constant expression}} \
// ref-note {{outside the range of representable values}} \
namespace PrimitiveEmptyInitList {
constexpr int a = {};
static_assert(a == 0, "");
constexpr bool b = {};
static_assert(!b, "");
constexpr double d = {};
static_assert(d == 0.0, "");
}


enum E {};
constexpr E e = static_cast<E>(0);
Expand Down

0 comments on commit 52a55a7

Please sign in to comment.