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