diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -463,7 +463,10 @@ return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue()); } Value *VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E) { - return EmitNullValue(E->getType()); + // [expr.type.conv]: if the type is cv void and the initializer is () or {}, + // the expression is a prvalue of type void that performs no initialization. + QualType T = E->getType(); + return T->isVoidType() ? nullptr : EmitNullValue(T); } Value *VisitGNUNullExpr(const GNUNullExpr *E) { return EmitNullValue(E->getType()); diff --git a/clang/test/CodeGenCXX/value-init.cpp b/clang/test/CodeGenCXX/value-init.cpp --- a/clang/test/CodeGenCXX/value-init.cpp +++ b/clang/test/CodeGenCXX/value-init.cpp @@ -338,4 +338,12 @@ struct optional : optional_data_dtor_base, optional_assign_base {}; optional f(optional a) { return {optional(a)}; } } + +namespace PR48889 { + // Just make sure we don't hit an assertion, the IR is otherwise unchanged. + constexpr void f() {} + void g(bool b) { + return b ? f() : void(); + } +} #endif