@@ -3091,10 +3091,10 @@ void CastOperation::CheckCStyleCast() {
30913091 return ;
30923092 }
30933093
3094- // C23 6.5.4p4 :
3095- // The type nullptr_t shall not be converted to any type other than void,
3096- // bool, or a pointer type. No type other than nullptr_t shall be converted
3097- // to nullptr_t.
3094+ // C23 6.5.5p4 :
3095+ // ... The type nullptr_t shall not be converted to any type other than
3096+ // void, bool or a pointer type.If the target type is nullptr_t, the cast
3097+ // expression shall be a null pointer constant or have type nullptr_t.
30983098 if (SrcType->isNullPtrType ()) {
30993099 // FIXME: 6.3.2.4p2 says that nullptr_t can be converted to itself, but
31003100 // 6.5.4p4 is a constraint check and nullptr_t is not void, bool, or a
@@ -3115,24 +3115,20 @@ void CastOperation::CheckCStyleCast() {
31153115 Self.CurFPFeatureOverrides ());
31163116 }
31173117 }
3118- // C23 6.3.2.4p2: a null pointer constant or value of type nullptr_t may be
3119- // converted to nullptr_t.
3120- if (DestType->isNullPtrType ()) {
3121- if (!SrcType->isNullPtrType () &&
3122- !SrcExpr.get ()->isNullPointerConstant (Self.Context ,
3118+
3119+ if (DestType->isNullPtrType () && !SrcType->isNullPtrType ()) {
3120+ if (!SrcExpr.get ()->isNullPointerConstant (Self.Context ,
31233121 Expr::NPC_NeverValueDependent)) {
31243122 Self.Diag (SrcExpr.get ()->getExprLoc (), diag::err_nullptr_cast)
31253123 << /* type to nullptr*/ 1 << SrcType;
31263124 SrcExpr = ExprError ();
31273125 return ;
31283126 }
3129- if (!SrcType->isNullPtrType ()) {
3130- // Need to convert the source from whatever its type is to a null pointer
3131- // type first.
3132- SrcExpr = ImplicitCastExpr::Create (
3133- Self.Context , DestType, CK_NullToPointer, SrcExpr.get (), nullptr ,
3134- VK_PRValue, Self.CurFPFeatureOverrides ());
3135- }
3127+ // Need to convert the source from whatever its type is to a null pointer
3128+ // type first.
3129+ SrcExpr = ImplicitCastExpr::Create (Self.Context , DestType, CK_NullToPointer,
3130+ SrcExpr.get (), nullptr , VK_PRValue,
3131+ Self.CurFPFeatureOverrides ());
31363132 }
31373133
31383134 if (DestType->isExtVectorType ()) {
0 commit comments