forked from OSchip/llvm-project
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:
parent
c8e390c215
commit
4efdec0677
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue