Argyrios Kyrtzidis | ffe76dd | 2012-06-20 01:10:40 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fblocks -Werror %s |
Argyrios Kyrtzidis | d8b4216 | 2012-01-12 02:34:32 +0000 | [diff] [blame] | 2 | // DISABLE: mingw32 |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 3 | |
Argyrios Kyrtzidis | 4897787 | 2011-12-09 00:17:47 +0000 | [diff] [blame] | 4 | #if __has_feature(objc_arc) |
| 5 | #define NS_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode"))) |
| 6 | #else |
| 7 | #define NS_AUTOMATED_REFCOUNT_UNAVAILABLE |
| 8 | #endif |
| 9 | |
Fariborz Jahanian | 52b6236 | 2012-02-01 22:56:20 +0000 | [diff] [blame] | 10 | typedef const void * CFTypeRef; |
| 11 | CFTypeRef CFBridgingRetain(id X); |
| 12 | id CFBridgingRelease(CFTypeRef); |
| 13 | |
Argyrios Kyrtzidis | 4897787 | 2011-12-09 00:17:47 +0000 | [diff] [blame] | 14 | typedef int BOOL; |
| 15 | typedef unsigned NSUInteger; |
| 16 | |
| 17 | @protocol NSObject |
Ted Kremenek | d6cf912 | 2012-02-10 02:45:47 +0000 | [diff] [blame] | 18 | - (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE; |
Argyrios Kyrtzidis | 4897787 | 2011-12-09 00:17:47 +0000 | [diff] [blame] | 19 | - (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE; |
Ted Kremenek | d6cf912 | 2012-02-10 02:45:47 +0000 | [diff] [blame] | 20 | - (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE; |
Argyrios Kyrtzidis | 4897787 | 2011-12-09 00:17:47 +0000 | [diff] [blame] | 21 | - (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE; |
| 22 | @end |
| 23 | |
| 24 | @interface NSObject <NSObject> {} |
| 25 | - (id)init; |
| 26 | |
| 27 | + (id)new; |
| 28 | + (id)alloc; |
| 29 | - (void)dealloc; |
| 30 | |
| 31 | - (void)finalize; |
| 32 | |
| 33 | - (id)copy; |
| 34 | - (id)mutableCopy; |
| 35 | @end |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 36 | |
| 37 | typedef const struct __CFString * CFStringRef; |
| 38 | extern const CFStringRef kUTTypePlainText; |
| 39 | extern const CFStringRef kUTTypeRTF; |
| 40 | @class NSString; |
| 41 | @class A; |
| 42 | |
| 43 | struct UnsafeS { |
| 44 | A *__unsafe_unretained unsafeObj; |
| 45 | }; |
| 46 | |
| 47 | @interface A : NSObject |
Fariborz Jahanian | 1ea6744 | 2012-06-05 21:14:46 +0000 | [diff] [blame] | 48 | - (id)retain; // expected-note {{declaration has been explicitly marked unavailable here}} |
| 49 | - (id)retainCount; // expected-note {{declaration has been explicitly marked unavailable here}} |
| 50 | - (id)autorelease; // expected-note 2 {{declaration has been explicitly marked unavailable here}} |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 51 | - (id)init; |
| 52 | - (oneway void)release; |
| 53 | - (void)dealloc; |
| 54 | -(void)test; |
Argyrios Kyrtzidis | 82a921a | 2011-07-15 23:48:56 +0000 | [diff] [blame] | 55 | -(id)delegate; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 56 | @end |
| 57 | |
| 58 | @implementation A |
| 59 | -(void)test { |
| 60 | [super dealloc]; |
| 61 | } |
| 62 | -(void)dealloc { |
| 63 | [super dealloc]; |
| 64 | } |
| 65 | |
| 66 | - (id)retain { return self; } // expected-error {{ARC forbids implementation}} |
| 67 | - (id)retainCount { return self; } // expected-error {{ARC forbids implementation}} |
| 68 | - (id)autorelease { return self; } // expected-error {{ARC forbids implementation}} |
| 69 | - (oneway void)release { } // expected-error {{ARC forbids implementation}} |
Argyrios Kyrtzidis | 82a921a | 2011-07-15 23:48:56 +0000 | [diff] [blame] | 70 | |
| 71 | -(id)delegate { return self; } |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 72 | @end |
| 73 | |
Argyrios Kyrtzidis | 2c18ca0 | 2011-07-14 23:32:04 +0000 | [diff] [blame] | 74 | id global_foo; |
| 75 | |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 76 | void test1(A *a, BOOL b, struct UnsafeS *unsafeS) { |
Argyrios Kyrtzidis | 82a921a | 2011-07-15 23:48:56 +0000 | [diff] [blame] | 77 | [[a delegate] release]; // expected-error {{it is not safe to remove 'retain' message on the result of a 'delegate' message; the object that was passed to 'setDelegate:' may not be properly retained}} \ |
Ted Kremenek | d6cf912 | 2012-02-10 02:45:47 +0000 | [diff] [blame] | 78 | // expected-error {{ARC forbids explicit message send}} |
Argyrios Kyrtzidis | 82a921a | 2011-07-15 23:48:56 +0000 | [diff] [blame] | 79 | [a.delegate release]; // expected-error {{it is not safe to remove 'retain' message on the result of a 'delegate' message; the object that was passed to 'setDelegate:' may not be properly retained}} \ |
Ted Kremenek | d6cf912 | 2012-02-10 02:45:47 +0000 | [diff] [blame] | 80 | // expected-error {{ARC forbids explicit message send}} |
Argyrios Kyrtzidis | e0e4076 | 2011-07-14 21:26:49 +0000 | [diff] [blame] | 81 | [unsafeS->unsafeObj retain]; // expected-error {{it is not safe to remove 'retain' message on an __unsafe_unretained type}} \ |
Fariborz Jahanian | 1ea6744 | 2012-06-05 21:14:46 +0000 | [diff] [blame] | 82 | // expected-error {{ARC forbids explicit message send}} \ |
| 83 | // expected-error {{'retain' is unavailable}} |
Argyrios Kyrtzidis | 2cd5366 | 2011-07-14 22:46:12 +0000 | [diff] [blame] | 84 | id foo = [unsafeS->unsafeObj retain]; // no warning. |
Argyrios Kyrtzidis | 2c18ca0 | 2011-07-14 23:32:04 +0000 | [diff] [blame] | 85 | [global_foo retain]; // expected-error {{it is not safe to remove 'retain' message on a global variable}} \ |
Ted Kremenek | d6cf912 | 2012-02-10 02:45:47 +0000 | [diff] [blame] | 86 | // expected-error {{ARC forbids explicit message send}} |
Argyrios Kyrtzidis | 2c18ca0 | 2011-07-14 23:32:04 +0000 | [diff] [blame] | 87 | [global_foo release]; // expected-error {{it is not safe to remove 'release' message on a global variable}} \ |
Ted Kremenek | d6cf912 | 2012-02-10 02:45:47 +0000 | [diff] [blame] | 88 | // expected-error {{ARC forbids explicit message send}} |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 89 | [a dealloc]; |
| 90 | [a retain]; |
Fariborz Jahanian | 1ea6744 | 2012-06-05 21:14:46 +0000 | [diff] [blame] | 91 | [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}} \ |
| 92 | // expected-error {{'retainCount' is unavailable}} |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 93 | [a release]; |
Argyrios Kyrtzidis | 5a42a02 | 2012-05-21 17:48:31 +0000 | [diff] [blame] | 94 | [a autorelease]; // expected-error {{it is not safe to remove an unused 'autorelease' message; its receiver may be destroyed immediately}} \ |
Fariborz Jahanian | 1ea6744 | 2012-06-05 21:14:46 +0000 | [diff] [blame] | 95 | // expected-error {{ARC forbids explicit message send}} \ |
| 96 | // expected-error {{'autorelease' is unavailable}} |
Argyrios Kyrtzidis | 1b8fbd3 | 2012-05-23 21:50:04 +0000 | [diff] [blame] | 97 | [a autorelease]; // expected-error {{it is not safe to remove an unused 'autorelease' message; its receiver may be destroyed immediately}} \ |
Fariborz Jahanian | 1ea6744 | 2012-06-05 21:14:46 +0000 | [diff] [blame] | 98 | // expected-error {{ARC forbids explicit message send}} \ |
| 99 | // expected-error {{'autorelease' is unavailable}} |
Argyrios Kyrtzidis | 1b8fbd3 | 2012-05-23 21:50:04 +0000 | [diff] [blame] | 100 | a = 0; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 101 | |
| 102 | CFStringRef cfstr; |
| 103 | NSString *str = (NSString *)cfstr; // expected-error {{cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \ |
Fariborz Jahanian | 607f587 | 2012-07-27 21:34:23 +0000 | [diff] [blame] | 104 | // expected-note {{use __bridge to convert directly (no change in ownership)}} \ |
Fariborz Jahanian | 52b6236 | 2012-02-01 22:56:20 +0000 | [diff] [blame] | 105 | // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}} \ |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 106 | str = (NSString *)kUTTypePlainText; |
| 107 | str = b ? kUTTypeRTF : kUTTypePlainText; |
| 108 | str = (NSString *)(b ? kUTTypeRTF : kUTTypePlainText); |
| 109 | str = (NSString *)a; // no change. |
| 110 | |
| 111 | SEL s = @selector(retain); // expected-error {{ARC forbids use of 'retain' in a @selector}} |
| 112 | s = @selector(release); // expected-error {{ARC forbids use of 'release' in a @selector}} |
| 113 | s = @selector(autorelease); // expected-error {{ARC forbids use of 'autorelease' in a @selector}} |
| 114 | s = @selector(dealloc); // expected-error {{ARC forbids use of 'dealloc' in a @selector}} |
| 115 | |
Argyrios Kyrtzidis | b8b0313 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 116 | static id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}} |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | struct S { |
Douglas Gregor | bde67cf | 2013-01-28 20:13:44 +0000 | [diff] [blame] | 120 | A* a; // expected-error {{ARC forbids Objective-C objects in struct}} |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | @interface B |
| 124 | -(id)alloc; |
| 125 | - (id)initWithInt: (int) i; |
| 126 | @end |
| 127 | |
| 128 | void rdar8861761() { |
| 129 | B *o1 = [[B alloc] initWithInt:0]; |
| 130 | B *o2 = [B alloc]; |
| 131 | [o2 initWithInt:0]; |
| 132 | } |
| 133 | |
| 134 | @interface Test13 |
| 135 | - (id) init0; |
| 136 | - (void) noninit; |
| 137 | @end |
| 138 | @implementation Test13 |
| 139 | - (id) init0 { |
| 140 | self = 0; |
| 141 | } |
| 142 | - (void) noninit { |
| 143 | self = 0; // expected-error {{cannot assign to 'self' outside of a method in the init family}} |
| 144 | |
Fariborz Jahanian | a1eec4b | 2012-07-03 22:00:52 +0000 | [diff] [blame] | 145 | for (__strong id x in collection) { // expected-error {{use of undeclared identifier 'collection'}} |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 146 | x = 0; |
| 147 | } |
| 148 | } |
| 149 | @end |
| 150 | |
| 151 | void * cvt(id arg) |
| 152 | { |
| 153 | void* voidp_val; |
| 154 | (void)(int*)arg; // expected-error {{disallowed}} |
| 155 | (void)(id)arg; |
| 156 | (void)(__autoreleasing id*)arg; // expected-error {{disallowed}} |
Argyrios Kyrtzidis | 0a85183 | 2011-07-01 22:22:59 +0000 | [diff] [blame] | 157 | (void)(id*)arg; // expected-error {{disallowed}} |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 158 | |
| 159 | (void)(__autoreleasing id**)voidp_val; |
| 160 | (void)(void*)voidp_val; |
| 161 | (void)(void**)arg; // expected-error {{disallowed}} |
John McCall | 5acb0c9 | 2011-10-17 18:40:02 +0000 | [diff] [blame] | 162 | cvt((void*)arg); // expected-error 2 {{requires a bridged cast}} \ |
Fariborz Jahanian | 607f587 | 2012-07-27 21:34:23 +0000 | [diff] [blame] | 163 | // expected-note 2 {{use __bridge to}} expected-note {{use CFBridgingRelease call}} expected-note {{use CFBridgingRetain call}} |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 164 | cvt(0); |
| 165 | (void)(__strong id**)(0); |
Fariborz Jahanian | 607f587 | 2012-07-27 21:34:23 +0000 | [diff] [blame] | 166 | return arg; // expected-error {{requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgingRetain call}} |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | |
| 170 | void test12(id collection) { |
| 171 | for (id x in collection) { |
| 172 | x = 0; |
| 173 | } |
| 174 | |
| 175 | for (__strong id x in collection) { |
| 176 | x = 0; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | void test6(unsigned cond) { |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 181 | switch (cond) { |
| 182 | case 0: |
| 183 | ; |
Argyrios Kyrtzidis | 4ce831c | 2013-01-08 00:58:25 +0000 | [diff] [blame] | 184 | id x; // expected-note {{jump bypasses initialization of retaining variable}} |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 185 | |
Argyrios Kyrtzidis | 4ce831c | 2013-01-08 00:58:25 +0000 | [diff] [blame] | 186 | case 1: // expected-error {{switch case is in protected scope}} |
| 187 | x = 0; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 188 | break; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | @class Test8_incomplete; |
| 193 | @interface Test8_complete @end; |
| 194 | @interface Test8_super @end; |
| 195 | @interface Test8 : Test8_super |
| 196 | - (id) init00; |
| 197 | - (id) init01; // expected-note {{declaration in interface}} |
| 198 | - (id) init02; |
| 199 | - (id) init03; // covariance |
| 200 | - (id) init04; // covariance |
| 201 | - (id) init05; |
| 202 | |
| 203 | - (void) init10; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} |
| 204 | - (void) init11; |
| 205 | - (void) init12; |
| 206 | - (void) init13; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} |
| 207 | - (void) init14; // expected-note {{declaration in interface is not in the 'init' family because its result type is not an object pointer}} |
| 208 | - (void) init15; |
| 209 | |
| 210 | // These should be invalid to actually call. |
| 211 | - (Test8_incomplete*) init20; |
| 212 | - (Test8_incomplete*) init21; // expected-note {{declaration in interface}} |
| 213 | - (Test8_incomplete*) init22; |
| 214 | - (Test8_incomplete*) init23; |
| 215 | - (Test8_incomplete*) init24; |
| 216 | - (Test8_incomplete*) init25; |
| 217 | |
| 218 | - (Test8_super*) init30; // id exception to covariance |
| 219 | - (Test8_super*) init31; // expected-note {{declaration in interface}} |
| 220 | - (Test8_super*) init32; |
| 221 | - (Test8_super*) init33; |
| 222 | - (Test8_super*) init34; // covariance |
| 223 | - (Test8_super*) init35; |
| 224 | |
| 225 | - (Test8*) init40; // id exception to covariance |
| 226 | - (Test8*) init41; // expected-note {{declaration in interface}} |
| 227 | - (Test8*) init42; |
| 228 | - (Test8*) init43; // this should be a warning, but that's a general language thing, not an ARC thing |
| 229 | - (Test8*) init44; |
| 230 | - (Test8*) init45; |
| 231 | |
| 232 | - (Test8_complete*) init50; // expected-error {{init methods must return a type related to the receiver type}} |
| 233 | - (Test8_complete*) init51; // expected-error {{init methods must return a type related to the receiver type}} |
| 234 | - (Test8_complete*) init52; // expected-error {{init methods must return a type related to the receiver type}} |
| 235 | - (Test8_complete*) init53; // expected-error {{init methods must return a type related to the receiver type}} |
| 236 | - (Test8_complete*) init54; // expected-error {{init methods must return a type related to the receiver type}} |
| 237 | - (Test8_complete*) init55; // expected-error {{init methods must return a type related to the receiver type}} |
| 238 | @end |
| 239 | @implementation Test8 |
| 240 | - (id) init00 { return 0; } |
| 241 | - (id) init10 { return 0; } // expected-error {{method implementation does not match its declaration}} |
| 242 | - (id) init20 { return 0; } |
| 243 | - (id) init30 { return 0; } |
| 244 | - (id) init40 { return 0; } |
| 245 | - (id) init50 { return 0; } |
| 246 | |
| 247 | - (void) init01 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} |
| 248 | - (void) init11 {} |
| 249 | - (void) init21 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} |
| 250 | - (void) init31 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} |
| 251 | - (void) init41 {} // expected-error {{method was declared as an 'init' method, but its implementation doesn't match because its result type is not an object pointer}} |
| 252 | - (void) init51 {} |
| 253 | |
| 254 | - (Test8_incomplete*) init02 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 255 | - (Test8_incomplete*) init12 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 256 | - (Test8_incomplete*) init22 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 257 | - (Test8_incomplete*) init32 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 258 | - (Test8_incomplete*) init42 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 259 | - (Test8_incomplete*) init52 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 260 | |
| 261 | - (Test8_super*) init03 { return 0; } |
| 262 | - (Test8_super*) init13 { return 0; } // expected-error {{method implementation does not match its declaration}} |
| 263 | - (Test8_super*) init23 { return 0; } |
| 264 | - (Test8_super*) init33 { return 0; } |
| 265 | - (Test8_super*) init43 { return 0; } |
| 266 | - (Test8_super*) init53 { return 0; } |
| 267 | |
| 268 | - (Test8*) init04 { return 0; } |
| 269 | - (Test8*) init14 { return 0; } // expected-error {{method implementation does not match its declaration}} |
| 270 | - (Test8*) init24 { return 0; } |
| 271 | - (Test8*) init34 { return 0; } |
| 272 | - (Test8*) init44 { return 0; } |
| 273 | - (Test8*) init54 { return 0; } |
| 274 | |
| 275 | - (Test8_complete*) init05 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 276 | - (Test8_complete*) init15 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 277 | - (Test8_complete*) init25 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 278 | - (Test8_complete*) init35 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 279 | - (Test8_complete*) init45 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 280 | - (Test8_complete*) init55 { return 0; } // expected-error {{init methods must return a type related to the receiver type}} |
| 281 | @end |
| 282 | |
| 283 | @class Test9_incomplete; |
| 284 | @interface Test9 |
| 285 | - (Test9_incomplete*) init1; // expected-error {{init methods must return a type related to the receiver type}} |
| 286 | - (Test9_incomplete*) init2; |
| 287 | @end |
| 288 | id test9(Test9 *v) { |
| 289 | return [v init1]; |
| 290 | } |
| 291 | |
| 292 | // rdar://9491791 |
| 293 | void rdar9491791(int p) { |
| 294 | switch (p) { |
| 295 | case 3:; |
Argyrios Kyrtzidis | ea2224d | 2013-01-04 18:30:08 +0000 | [diff] [blame] | 296 | NSObject *o = [[NSObject alloc] init]; |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 297 | [o release]; |
| 298 | break; |
Argyrios Kyrtzidis | ea2224d | 2013-01-04 18:30:08 +0000 | [diff] [blame] | 299 | default: |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 300 | break; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | #define RELEASE_MACRO(x) do { [x release]; } while(1) |
| 305 | |
| 306 | // rdar://9504750 |
| 307 | void rdar9504750(id p) { |
Ted Kremenek | d6cf912 | 2012-02-10 02:45:47 +0000 | [diff] [blame] | 308 | RELEASE_MACRO(p); // expected-error {{ARC forbids explicit message send of 'release'}} |
John McCall | 8f0e8d2 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 309 | } |
Argyrios Kyrtzidis | 7bf952e | 2011-06-22 18:03:59 +0000 | [diff] [blame] | 310 | |
| 311 | // rdar://8939557 |
| 312 | @interface TestReadonlyProperty : NSObject |
| 313 | @property(assign,readonly) NSObject *value; |
| 314 | @end |
| 315 | |
| 316 | @implementation TestReadonlyProperty |
| 317 | @synthesize value; |
| 318 | - (void)viewDidLoad { |
| 319 | value = [NSObject new]; // expected-error {{assigning retained object}} |
| 320 | } |
| 321 | @end |
Argyrios Kyrtzidis | cf79eba | 2011-06-24 18:41:23 +0000 | [diff] [blame] | 322 | |
| 323 | // rdar://9601437 |
| 324 | @interface I9601437 { |
| 325 | __unsafe_unretained id x; |
| 326 | } |
| 327 | -(void)Meth; |
| 328 | @end |
| 329 | |
| 330 | @implementation I9601437 |
| 331 | -(void)Meth { |
| 332 | self->x = [NSObject new]; // expected-error {{assigning retained object}} |
| 333 | } |
| 334 | @end |
Argyrios Kyrtzidis | ffe76dd | 2012-06-20 01:10:40 +0000 | [diff] [blame] | 335 | |
Argyrios Kyrtzidis | 2401676 | 2013-08-09 20:20:25 +0000 | [diff] [blame] | 336 | @interface Test10 : NSObject { |
| 337 | CFStringRef cfstr; |
| 338 | } |
Argyrios Kyrtzidis | ffe76dd | 2012-06-20 01:10:40 +0000 | [diff] [blame] | 339 | @property (retain) id prop; |
| 340 | -(void)foo; |
| 341 | @end |
| 342 | |
| 343 | void test(Test10 *x) { |
| 344 | x.prop = ^{ [x foo]; }; // expected-warning {{likely to lead to a retain cycle}} \ |
| 345 | // expected-note {{retained by the captured object}} |
| 346 | } |
Argyrios Kyrtzidis | 2401676 | 2013-08-09 20:20:25 +0000 | [diff] [blame] | 347 | |
| 348 | @implementation Test10 |
| 349 | -(void)foo { |
| 350 | ^{ |
| 351 | NSString *str = (NSString *)cfstr; // expected-error {{cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \ |
| 352 | // expected-note {{use __bridge to convert directly (no change in ownership)}} \ |
| 353 | // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}} |
| 354 | }; |
| 355 | } |
| 356 | @end |