From: Fariborz Jahanian Date: Thu, 13 May 2010 17:19:25 +0000 (+0000) Subject: Objective-C++ Sema. Fix a bug in instantiation of receivers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ba606199be8056ae83596260bd6fd5872942905;p=clang Objective-C++ Sema. Fix a bug in instantiation of receivers. Completes radar 7963410. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103719 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 3853e911e7..eb60011ec3 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -977,7 +977,12 @@ Sema::OwningExprResult Sema::BuildInstanceMessage(ExprArg ReceiverE, CastExpr::CK_IntegralToPointer); ReceiverType = Receiver->getType(); } - else if (!PerformContextuallyConvertToObjCId(Receiver)) { + else if (getLangOptions().CPlusPlus && + !PerformContextuallyConvertToObjCId(Receiver)) { + if (ImplicitCastExpr *ICE = dyn_cast(Receiver)) { + Receiver = ICE->getSubExpr(); + ReceiverType = Receiver->getType(); + } return BuildInstanceMessage(Owned(Receiver), ReceiverType, SuperLoc, diff --git a/test/SemaObjCXX/conversion-to-objc-pointer-2.mm b/test/SemaObjCXX/conversion-to-objc-pointer-2.mm new file mode 100644 index 0000000000..5277d101f5 --- /dev/null +++ b/test/SemaObjCXX/conversion-to-objc-pointer-2.mm @@ -0,0 +1,87 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar: // 7963410 + +@protocol NSObject @end +@interface NSObject +- (id)init; +- (id) alloc; +- (id) autorelease; +@end + +template +class TNSAutoRef +{ +public: + TNSAutoRef(T t) + : fRef(t) + { } + + ~TNSAutoRef() + { } + + operator T() const + { return fRef; } + +private: + T fRef; +}; + + +#pragma mark - + + +@protocol TFooProtocol + +- (void) foo; +@end + + +#pragma mark - + + +@interface TFoo : NSObject + +- (void) setBlah: (id)blah; +@end + + +#pragma mark - + + +@implementation TFoo + +- (void) setBlah: (id)blah + { } +@end + + +#pragma mark - + + +@interface TBar : NSObject + +- (void) setBlah: (id)blah; +@end + +#pragma mark - + + +@implementation TBar + +- (void) setBlah: (id)blah + { } +@end + + +#pragma mark - + + +int main (int argc, const char * argv[]) { + + NSObject* object1 = [[[NSObject alloc] init] autorelease]; + TNSAutoRef object2([[NSObject alloc] init]); + TNSAutoRef bar([[TBar alloc] init]); + [bar setBlah: object1]; // <== Does not compile. It should. + [bar setBlah: object2]; // <== Does not compile. It should. + return 0; +} diff --git a/test/SemaObjCXX/conversion-to-objc-pointer.mm b/test/SemaObjCXX/conversion-to-objc-pointer.mm index 2f146ce206..235aaac8d0 100644 --- a/test/SemaObjCXX/conversion-to-objc-pointer.mm +++ b/test/SemaObjCXX/conversion-to-objc-pointer.mm @@ -28,20 +28,19 @@ private: @end @interface TFoo : NSObject - - (void) foo; @end @implementation TFoo - -- (void) foo - {} +- (void) foo {} @end @interface TBar : NSObject +- (void) foo; @end @implementation TBar +- (void) foo {} @end int main () {