[PATCH] D22391: [Sema] Add warning for implicitly casting a null constant to a non null pointer type

Jordan Rose via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 22 18:14:20 PDT 2017


jordan_rose added a comment.

This looks like it's only coming up for declarations. What about assignments?

  int x;
  int * _Nonnull p = &x;
  p = NULL; // warn here?



================
Comment at: lib/Sema/SemaExpr.cpp:7117
+    if (E && S.checkNonNullExpr(E))
+      return NullabilityKind::Nullable;
+
----------------
This isn't quite correct, unfortunately. `(_Nonnull id)nil` should be considered non-nullable, since it's the canonical way to avoid all these warnings. It might just be good enough to move this check below the `getNullability` one, though.


https://reviews.llvm.org/D22391





More information about the cfe-commits mailing list