]> granicus.if.org Git - clang/commitdiff
Objective-C++ Sema. Fix a bug in instantiation of receivers.
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 13 May 2010 17:19:25 +0000 (17:19 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 13 May 2010 17:19:25 +0000 (17:19 +0000)
Completes radar 7963410.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103719 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprObjC.cpp
test/SemaObjCXX/conversion-to-objc-pointer-2.mm [new file with mode: 0644]
test/SemaObjCXX/conversion-to-objc-pointer.mm

index 3853e911e720e8594eef472fa5dfedfe11d8eeaa..eb60011ec3d6c56f2bac39b4fbe0cae56fd5e5c6 100644 (file)
@@ -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<ImplicitCastExpr>(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 (file)
index 0000000..5277d10
--- /dev/null
@@ -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 T>
+class TNSAutoRef
+{
+public:
+       TNSAutoRef(T t)
+               :       fRef(t)
+               { }
+
+       ~TNSAutoRef()
+               { }
+
+       operator T() const
+               { return fRef; }
+
+private:
+       T fRef;
+};
+
+
+#pragma mark -
+
+
+@protocol TFooProtocol <NSObject>
+
+- (void) foo;
+@end
+
+
+#pragma mark -
+
+
+@interface TFoo : NSObject
+
+- (void) setBlah: (id<TFooProtocol>)blah;
+@end
+
+
+#pragma mark -
+
+
+@implementation TFoo
+
+- (void) setBlah: (id<TFooProtocol>)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<NSObject*> object2([[NSObject alloc] init]);
+       TNSAutoRef<TBar*> bar([[TBar alloc] init]);
+       [bar setBlah: object1];                         // <== Does not compile.  It should.
+       [bar setBlah: object2];                         // <== Does not compile.  It should.
+       return 0;
+}
index 2f146ce2061b8d34e84765c97728ba3a9925792b..235aaac8d09cdb3277b23613fd9574e686447ff6 100644 (file)
@@ -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 () {