Teach Sema::CheckAssignmentConstraints() to allow assignments between id and block pointer types (^{}).

llvm-svn: 56793
This commit is contained in:
Steve Naroff 2008-09-29 18:10:17 +00:00
parent 82237f2f42
commit 32d072ca45
2 changed files with 20 additions and 2 deletions

View 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);

View 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);
}