1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.RetainCount -verify -Wno-objc-root-class %s
3 typedef signed char BOOL;
4 typedef unsigned int NSUInteger;
14 @interface Subscriptable : NSObject
15 - (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)index;
16 - (id)objectAtIndexedSubscript:(NSUInteger)index;
18 - (void)setObject:(id)obj forKeyedSubscript:(id)key;
19 - (id)objectForKeyedSubscript:(id)key;
22 @interface Test : Subscriptable
27 // <rdar://problem/6946338> for subscripting
28 - (id)storeDoesNotRetain {
29 Test *cell = [[[Test alloc] init] autorelease];
31 NSObject *string1 = [[NSObject alloc] init]; // expected-warning {{Potential leak}}
39 // <rdar://problem/8824416> for subscripting
40 - (id)getDoesNotRetain:(BOOL)keyed {
42 return [self[self] autorelease]; // expected-warning{{Object autoreleased too many times}}
44 return [self[0] autorelease]; // expected-warning{{Object autoreleased too many times}}
47 // <rdar://problem/9241180> for subscripting
48 - (id)testUninitializedObject:(BOOL)keyed {
51 if (o[self]) // expected-warning {{Subscript access on an uninitialized object pointer}}
52 return o; // no-warning (sink)
54 if (o[0]) // expected-warning {{Subscript access on an uninitialized object pointer}}
55 return o; // no-warning (sink)
60 - (void)testUninitializedArgument:(id)input testCase:(unsigned)testCase {
66 self[0] = o; // expected-warning {{Argument for subscript setter is an uninitialized value}}
69 self[i] = input; // expected-warning {{Subscript index is an uninitialized value}}
72 (void)self[i]; // expected-warning {{Subscript index is an uninitialized value}}
75 self[input] = o; // expected-warning {{Argument for subscript setter is an uninitialized value}}
78 self[o] = input; // expected-warning {{Subscript index is an uninitialized value}}
81 (void)self[o]; // expected-warning {{Subscript index is an uninitialized value}}