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 @@ -222,7 +222,8 @@ return this->emitNE(PtrT, CE); } - case CK_IntegralComplexToBoolean: { + case CK_IntegralComplexToBoolean: + case CK_FloatingComplexToBoolean: { std::optional ElemT = classifyComplexElementType(SubExpr->getType()); if (!ElemT) @@ -237,8 +238,14 @@ return false; if (!this->emitLoadPop(*ElemT, CE)) return false; - if (!this->emitCast(*ElemT, PT_Bool, CE)) - return false; + if (*ElemT == PT_Float) { + if (!this->emitCastFloatingIntegral(PT_Bool, CE)) + return false; + } else { + if (!this->emitCast(*ElemT, PT_Bool, CE)) + return false; + } + // We now have the bool value of E[0] on the stack. LabelTy LabelTrue = this->getLabel(); if (!this->jumpTrue(LabelTrue)) @@ -250,8 +257,13 @@ return false; if (!this->emitLoadPop(*ElemT, CE)) return false; - if (!this->emitCast(*ElemT, PT_Bool, CE)) - return false; + if (*ElemT == PT_Float) { + if (!this->emitCastFloatingIntegral(PT_Bool, CE)) + return false; + } else { + if (!this->emitCast(*ElemT, PT_Bool, CE)) + return false; + } // Leave the boolean value of E[1] on the stack. LabelTy EndLabel = this->getLabel(); this->jump(EndLabel); diff --git a/clang/test/AST/Interp/complex.cpp b/clang/test/AST/Interp/complex.cpp --- a/clang/test/AST/Interp/complex.cpp +++ b/clang/test/AST/Interp/complex.cpp @@ -66,4 +66,11 @@ static_assert(F5, ""); constexpr _Complex unsigned char F6 = {0, 0}; static_assert(!F6, ""); + + constexpr _Complex float F7 = {0, 1}; + static_assert(F7, ""); + constexpr _Complex float F8 = {1, 0}; + static_assert(F8, ""); + constexpr _Complex double F9 = {0, 0}; + static_assert(!F9, ""); }