]> granicus.if.org Git - clang/commitdiff
Teach Sema::CheckAssignmentConstraints() to allow assignments between id and block...
authorSteve Naroff <snaroff@apple.com>
Mon, 29 Sep 2008 18:10:17 +0000 (18:10 +0000)
committerSteve Naroff <snaroff@apple.com>
Mon, 29 Sep 2008 18:10:17 +0000 (18:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56793 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/block-as-object.m

index 269db214b70a2568e774f836eea0f80515af171d..b19da68abee205c406433c069d8565e65678a739 100644 (file)
@@ -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);
       
index 2bfb9c37e6120d1091cf4b3d749df5eda95b2450..8afab4c3f7d09c9fcb61bafe108c5ce8862bcba2 100644 (file)
@@ -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);
+}