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