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 - (id)storeDoesNotRetain {
28 Test *cell = [[[Test alloc] init] autorelease];
30 NSObject *string1 = [[NSObject alloc] init]; // expected-warning {{Potential leak}}
38 - (id)getDoesNotRetain:(BOOL)keyed {
40 return [self[self] autorelease]; // expected-warning{{Object autoreleased too many times}}
42 return [self[0] autorelease]; // expected-warning{{Object autoreleased too many times}}
45 - (id)testUninitializedObject:(BOOL)keyed {
48 if (o[self]) // expected-warning {{Subscript access on an uninitialized object pointer}}
49 return o; // no-warning (sink)
51 if (o[0]) // expected-warning {{Subscript access on an uninitialized object pointer}}
52 return o; // no-warning (sink)
57 - (void)testUninitializedArgument:(id)input testCase:(unsigned)testCase {
63 self[0] = o; // expected-warning {{Argument for subscript setter is an uninitialized value}}
66 self[i] = input; // expected-warning {{Subscript index is an uninitialized value}}
69 (void)self[i]; // expected-warning {{Subscript index is an uninitialized value}}
72 self[input] = o; // expected-warning {{Argument for subscript setter is an uninitialized value}}
75 self[o] = input; // expected-warning {{Subscript index is an uninitialized value}}
78 (void)self[o]; // expected-warning {{Subscript index is an uninitialized value}}