diff options
author | Steve Naroff <snaroff@apple.com> | 2008-09-29 18:10:17 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2008-09-29 18:10:17 +0000 |
commit | b440686eeed95c618ead89011d3814671b13ff6e (patch) | |
tree | 9fb1c9e561688bf93789649682c1a16c5fdf4102 | |
parent | 6c4088e5fc0ce98bf3213d47f6f38bfbfa20c813 (diff) |
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
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 14 | ||||
-rw-r--r-- | test/Sema/block-as-object.m | 8 |
2 files changed, 20 insertions, 2 deletions
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<PointerType>(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); +} |