1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// RUN: %clang_cc1 -arcmt-action=check -verify -triple x86_64-apple-darwin10 %s
#if __has_feature(objc_arr)
#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode")))
#else
#define NS_AUTOMATED_REFCOUNT_UNAVAILABLE
#endif
typedef struct _NSZone NSZone;
typedef int BOOL;
typedef unsigned NSUInteger;
@protocol NSObject
- (BOOL)isEqual:(id)object;
- (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
- (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
- (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
- (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
- (NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
@end
@protocol NSCopying
- (id)copyWithZone:(NSZone *)zone;
@end
@protocol NSMutableCopying
- (id)mutableCopyWithZone:(NSZone *)zone;
@end
@interface NSObject <NSObject> {}
- (id)init;
+ (id)new;
+ (id)allocWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
+ (id)alloc;
- (void)dealloc;
- (void)finalize;
- (id)copy;
- (id)mutableCopy;
+ (id)copyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
+ (id)mutableCopyWithZone:(NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
@end
extern void NSRecycleZone(NSZone *zone);
NS_AUTOMATED_REFCOUNT_UNAVAILABLE
@interface NSAutoreleasePool : NSObject { // expected-note 13 {{marked unavailable here}}
@private
void *_token;
void *_reserved3;
void *_reserved2;
void *_reserved;
}
+ (void)addObject:(id)anObject;
- (void)addObject:(id)anObject;
- (void)drain;
@end
void NSLog(id, ...);
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSAutoreleasePool *chunkPool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}}
while (argc) {
[chunkPool release];
// the following pool was not released in this scope, don't touch it.
chunkPool = [[NSAutoreleasePool alloc] init]; // expected-error {{'NSAutoreleasePool' is unavailable}}
}
[chunkPool drain];
[pool drain];
return 0;
}
void f(void) {
NSAutoreleasePool * pool; // expected-error {{'NSAutoreleasePool' is unavailable}}
for (int i=0; i != 10; ++i) {
id x = pool; // We won't touch a NSAutoreleasePool if we can't safely
// remove all the references to it.
}
pool = [[NSAutoreleasePool alloc] init]; // expected-error {{'NSAutoreleasePool' is unavailable}}
NSLog(@"%s", "YES");
[pool release];
}
void f2(void) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \
// expected-note {{scope begins here}}
// 'x' is declared inside the "pool scope" but used outside it, if we create
// a @autorelease scope it will be undefined outside it so don't touch the pool.
int x = 0; // expected-note {{declared here}}
[pool release]; // expected-note {{scope ends here}}
++x; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}}
}
void f3(void) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \
// expected-note {{scope begins here}}
struct S { int x; }; // expected-note {{declared here}}
[pool release]; // expected-note {{scope ends here}}
struct S *var; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}}
var->x = 0;
}
void f4(void) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \
// expected-note {{scope begins here}}
enum { Bar }; // expected-note {{declared here}}
[pool release]; // expected-note {{scope ends here}}
int x = Bar; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}}
}
void f5(void) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // expected-error 2 {{'NSAutoreleasePool' is unavailable}} \
// expected-note {{scope begins here}}
typedef int Bar; // expected-note {{declared here}}
[pool release]; // expected-note {{scope ends here}}
Bar x; // expected-error {{a name is referenced outside the NSAutoreleasePool scope that it was declared in}}
}
|