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 @@ -279,10 +279,15 @@ template bool ByteCodeExprGen::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) { - if (std::optional T = classify(E)) - return this->emitZero(*T, E); + std::optional T = classify(E); - return false; + if (!T) + return false; + + if (E->getType()->isPointerType()) + return this->emitNullPtr(E); + + return this->emitZero(*T, E); } template diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -49,7 +49,10 @@ static_assert(!nu, ""); }; - +constexpr int UninitI; // expected-error {{must be initialized by a constant expression}} \ + // ref-error {{must be initialized by a constant expression}} +constexpr int *UninitPtr; // expected-error {{must be initialized by a constant expression}} \ + // ref-error {{must be initialized by a constant expression}} constexpr bool getTrue() { return true; } constexpr bool getFalse() { return false; }