From: Steve Naroff Date: Mon, 29 Sep 2008 18:10:17 +0000 (+0000) Subject: Teach Sema::CheckAssignmentConstraints() to allow assignments between id and block... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b440686eeed95c618ead89011d3814671b13ff6e;p=clang Teach Sema::CheckAssignmentConstraints() to allow assignments between id and block pointer types (^{}). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56793 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 269db214b7..b19da68abe 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1653,10 +1653,15 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { if (isa(rhsType)) return CheckPointerTypesForAssignment(lhsType, rhsType); - if (rhsType->getAsBlockPointerType()) + if (rhsType->getAsBlockPointerType()) { if (lhsType->getAsPointerType()->getPointeeType()->isVoidType()) return BlockVoidPointer; - + + // Treat block pointers as objects. + if (getLangOptions().ObjC1 && + lhsType == Context.getCanonicalType(Context.getObjCIdType())) + return Compatible; + } return Incompatible; } @@ -1664,6 +1669,11 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { if (rhsType->isIntegerType()) return IntToPointer; + // Treat block pointers as objects. + if (getLangOptions().ObjC1 && + rhsType == Context.getCanonicalType(Context.getObjCIdType())) + return Compatible; + if (rhsType->isBlockPointerType()) return CheckBlockPointerTypesForAssignment(lhsType, rhsType); diff --git a/test/Sema/block-as-object.m b/test/Sema/block-as-object.m index 2bfb9c37e6..8afab4c3f7 100644 --- a/test/Sema/block-as-object.m +++ b/test/Sema/block-as-object.m @@ -10,3 +10,11 @@ void foo(MyBlock b) { id bar = [b copy]; } +void foo2(id b) { +} + +void foo3(void (^block)(void)) { + foo2(block); + id x; + foo(x); +}