diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index b727865427054..8a756e4fc2db4 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -167,14 +167,16 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr *CE) { } case CK_PointerToBoolean: { + PrimType PtrT = classifyPrim(SubExpr->getType()); + // Just emit p != nullptr for this. if (!this->visit(SubExpr)) return false; - if (!this->emitNullPtr(CE)) + if (!this->emitNull(PtrT, CE)) return false; - return this->emitNEPtr(CE); + return this->emitNE(PtrT, CE); } case CK_ToVoid: diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 3540791917fab..e1dd73b695868 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -176,6 +176,13 @@ namespace FunctionReturnType { constexpr S s{ 12 }; static_assert(s.fp == nullptr, ""); // zero-initialized function pointer. + + constexpr int (*op)(int, int) = add; + constexpr bool b = op; + static_assert(op, ""); + static_assert(!!op, ""); + constexpr int (*op2)(int, int) = nullptr; + static_assert(!op2, ""); } namespace Comparison {