This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG52a55a717838: [clang][Interp] Allow zero-init of primitives with an empty init list (authored by tbaeder).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158595/new/ https://reviews.llvm.org/D158595 Files: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/literals.cpp Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -91,6 +91,15 @@ // 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); Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -571,8 +571,10 @@ // 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]); }
Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -91,6 +91,15 @@ // 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); Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -571,8 +571,10 @@ // 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]); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits