[clang] [C23] Allow casting from a null pointer constant to nullptr_t (PR #133742)

James Y Knight via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 31 13:46:05 PDT 2025


================
@@ -3115,11 +3115,24 @@ void CastOperation::CheckCStyleCast() {
                                          Self.CurFPFeatureOverrides());
     }
   }
-  if (DestType->isNullPtrType() && !SrcType->isNullPtrType()) {
-    Self.Diag(SrcExpr.get()->getExprLoc(), diag::err_nullptr_cast)
-        << /*type to nullptr*/ 1 << SrcType;
-    SrcExpr = ExprError();
-    return;
+  // C23 6.3.2.4p2: a null pointer constant or value of type nullptr_t may be
+  // converted to nullptr_t.
+  if (DestType->isNullPtrType()) {
----------------
jyknight wrote:

Can make the first line `if (DestType->isNullPtrType() && !SrcType->isNullPtrType()) {`, to simplify.

https://github.com/llvm/llvm-project/pull/133742


More information about the cfe-commits mailing list