diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -953,8 +953,10 @@ return this->emitNullPtr(E); case PT_FnPtr: return this->emitNullFnPtr(E); - case PT_Float: - assert(false); + case PT_Float: { + return this->emitConstFloat( + APFloat::getZero(Ctx.getFloatSemantics(E->getType())), E); + } } llvm_unreachable("unknown primitive type"); } diff --git a/clang/test/AST/Interp/floats.cpp b/clang/test/AST/Interp/floats.cpp --- a/clang/test/AST/Interp/floats.cpp +++ b/clang/test/AST/Interp/floats.cpp @@ -78,3 +78,17 @@ } static_assert(f2() == __FLT_MAX__, ""); } + +namespace ZeroInit { + template + struct A { + int a; + FloatT f; + }; + + constexpr A a{12}; + static_assert(a.f == 0.0f); + + constexpr A b{12}; + static_assert(a.f == 0.0); +};