From: Fariborz Jahanian Date: Mon, 18 Jan 2010 22:59:22 +0000 (+0000) Subject: Allow conversion of pointer to an objective-c pointer to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=83b7b31fff0b3b0d6519676c5738b61058202d88;p=clang Allow conversion of pointer to an objective-c pointer to a similar pointer. Fixes radar 7552179. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93803 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 884192b733..d710d96586 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -1100,7 +1100,7 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, bool &IncompatibleObjC) { if (!getLangOptions().ObjC1) return false; - + // First, we handle all conversions on ObjC object pointer types. const ObjCObjectPointerType* ToObjCPtr = ToType->getAs(); const ObjCObjectPointerType *FromObjCPtr = @@ -1164,6 +1164,16 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, ConvertedType = ToType; return true; } + // Allow conversion of pointee being objective-c pointer to another one; + // as in I* to id. + if (FromPointeeType->getAs() && + ToPointeeType->getAs() && + isObjCPointerConversion(FromPointeeType, ToPointeeType, ConvertedType, + IncompatibleObjC)) { + ConvertedType = ToType; + return true; + } + // If we have pointers to functions or blocks, check whether the only // differences in the argument and result types are in Objective-C // pointer conversions. If so, we permit the conversion (but diff --git a/test/SemaObjCXX/pointer-to-objc-pointer-conv.mm b/test/SemaObjCXX/pointer-to-objc-pointer-conv.mm new file mode 100644 index 0000000000..80383ebfd8 --- /dev/null +++ b/test/SemaObjCXX/pointer-to-objc-pointer-conv.mm @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@interface G +@end + +@interface F +- (void)bar:(id *)objects; +- (void)foo:(G**)objects; +@end + + +void a() { + F *b; + G **keys; + [b bar:keys]; + + id *PID; + [b foo:PID]; + +} +