In objective-c++ land, a block pointer is another object pointer.

So, casting a generic object pointer ('id' or 'Class') to the
block pointer is allowed. Fixes radar 7562285.

llvm-svn: 94045
This commit is contained in:
Fariborz Jahanian 2010-01-20 22:54:38 +00:00
parent c8e390c215
commit 4efdec0677
2 changed files with 32 additions and 1 deletions

View File

@ -1141,8 +1141,16 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType,
QualType ToPointeeType;
if (const PointerType *ToCPtr = ToType->getAs<PointerType>())
ToPointeeType = ToCPtr->getPointeeType();
else if (const BlockPointerType *ToBlockPtr = ToType->getAs<BlockPointerType>())
else if (const BlockPointerType *ToBlockPtr =
ToType->getAs<BlockPointerType>()) {
// Objective C++: We're able to convert from a pointer to an any object
// to a block pointer type.
if (FromObjCPtr && FromObjCPtr->isObjCBuiltinType()) {
ConvertedType = ToType;
return true;
}
ToPointeeType = ToBlockPtr->getPointeeType();
}
else
return false;

View File

@ -0,0 +1,23 @@
// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s
// radar 7562285
typedef int (^blocktype)(int a, int b);
@interface A {
A* a;
id b;
Class c;
}
- (blocktype)Meth;
@end
@implementation A
- (blocktype)Meth {
if (b)
return (blocktype)b;
else if (a)
return (blocktype)a; // expected-error {{C-style cast from 'A *' to 'blocktype' (aka 'int (^)(int, int)') is not allowed}}
else
return (blocktype)c;
}
@end