diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 823bef7a8c19e..c813f9b6d9991 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -571,8 +571,10 @@ bool ByteCodeExprGen::VisitInitListExpr(const InitListExpr *E) { // Primitive values. if (std::optional 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]); } diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index 562090d46b094..ceda59405ea91 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -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(0);