[cfe-commits] r94045 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaObjCXX/cstyle-block-pointer-cast.mm
Fariborz Jahanian
fjahanian at apple.com
Wed Jan 20 14:54:38 PST 2010
Author: fjahanian
Date: Wed Jan 20 16:54:38 2010
New Revision: 94045
URL: http://llvm.org/viewvc/llvm-project?rev=94045&view=rev
Log:
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.
Added:
cfe/trunk/test/SemaObjCXX/cstyle-block-pointer-cast.mm
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=94045&r1=94044&r2=94045&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Jan 20 16:54:38 2010
@@ -1141,8 +1141,16 @@
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;
Added: cfe/trunk/test/SemaObjCXX/cstyle-block-pointer-cast.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/cstyle-block-pointer-cast.mm?rev=94045&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/cstyle-block-pointer-cast.mm (added)
+++ cfe/trunk/test/SemaObjCXX/cstyle-block-pointer-cast.mm Wed Jan 20 16:54:38 2010
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s
+// radar 7562285
+
+typedef int (^blocktype)(int a, int b);
+
+ at interface A {
+ A* a;
+ id b;
+ Class c;
+}
+- (blocktype)Meth;
+ at end
+
+ at 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;
+}
+ at end
More information about the cfe-commits
mailing list