Home | History | Annotate | Download | only in SemaObjCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 // expected-no-diagnostics
      3 // rdar: // 7963410
      4 
      5 @protocol NSObject @end
      6 @interface NSObject
      7 - (id)init;
      8 - (id) alloc;
      9 - (id) autorelease;
     10 @end
     11 
     12 template<class T>
     13 class TNSAutoRef
     14 {
     15 public:
     16 	TNSAutoRef(T t)
     17 		:	fRef(t)
     18 		{ }
     19 
     20 	~TNSAutoRef()
     21 		{ }
     22 
     23 	operator T() const
     24 		{ return fRef; }
     25 
     26 private:
     27 	T fRef;
     28 };
     29 
     30 
     31 #pragma mark -
     32 
     33 
     34 @protocol TFooProtocol <NSObject>
     35 
     36 - (void) foo;
     37 @end
     38 
     39 
     40 #pragma mark -
     41 
     42 
     43 @interface TFoo : NSObject
     44 
     45 - (void) setBlah: (id<TFooProtocol>)blah;
     46 @end
     47 
     48 
     49 #pragma mark -
     50 
     51 
     52 @implementation TFoo
     53 
     54 - (void) setBlah: (id<TFooProtocol>)blah
     55 	{ }
     56 @end
     57 
     58 
     59 #pragma mark -
     60 
     61 
     62 @interface TBar : NSObject
     63 
     64 - (void) setBlah: (id)blah;
     65 @end
     66 
     67 #pragma mark -
     68 
     69 
     70 @implementation TBar
     71 
     72 - (void) setBlah: (id)blah
     73 	{ }
     74 @end
     75 
     76 
     77 #pragma mark -
     78 
     79 
     80 int main (int argc, const char * argv[]) {
     81 
     82 	NSObject* object1 = [[[NSObject alloc] init] autorelease];
     83 	TNSAutoRef<NSObject*> object2([[NSObject alloc] init]);
     84 	TNSAutoRef<TBar*> bar([[TBar alloc] init]);
     85 	[bar setBlah: object1];				// <== Does not compile.  It should.
     86         if (object1 == object2)
     87 	  [bar setBlah: object2];				// <== Does not compile.  It should.
     88 	return 0;
     89 }
     90