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 @@ -167,14 +167,16 @@ } 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 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -176,6 +176,13 @@ 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 {