[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
----------------
jyknight wrote:

The (not modified by this PR) comment for the previous stanza `C23 6.5.4p4:` is wrong. It's presumably from an old draft of C23, as it matches the _implementation_ we have, but not the actual standard. The section number is also different. It should now be (From N3299):

> C23 6.5.5p4:
> The type nullptr_t shall not be converted to any type other than void, bool or a
> pointer type. If the target type is nullptr_t, the cast expression shall be a null pointer constant or
> have type nullptr_t.

I think that one comment then covers both stanzas (again), and you don't need another comment here.

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


More information about the cfe-commits mailing list