[PATCH] D44580: Sema: allow comparison between blocks & block-compatible objc types

Dustin L. Howett via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 18 15:08:33 PDT 2018

DHowett-MSFT planned changes to this revision.
DHowett-MSFT marked an inline comment as done.
DHowett-MSFT added inline comments.

Comment at: lib/Sema/SemaExpr.cpp:7749
+    // id (or strictly compatible object type) -> T^
+    if (getLangOpts().ObjC1 && RHSType->isBlockCompatibleObjCPointerType(Context)) {
       Kind = CK_AnyPointerToBlockPointerCast;
theraven wrote:
> Do we want to allow implicit casts for all object types to block types for assignment, or only for null pointers?  We definitely want to allow `nil` to be assigned to a block type, but I would lean slightly to requiring an implicit cast.
> Ideally, I think we'd allow this but warn, because casting from an arbitrary ObjC type to a block incorrectly can cause exciting security vulnerabilities if it's done incorrectly and we should encourage people to check these casts (`nil` is always safe though - as long as somewhere else checks the nullability attributes).
I don't actually have a compelling use case for widening assignability here. I'm dropping this part of the patch.

I do think it should be valid, perhaps with a warning. It feels incorrect for there to be valid comparison cases that are not valid assignment cases (here), but that position doesn't hold up under scrutiny.

  rC Clang


More information about the cfe-commits mailing list