1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
3 typedef long int NSUInteger;
7 @interface NSMutableArray
9 - (void)addObject:(id)object;
10 - (void)insertObject:(id)object atIndex:(NSUInteger)index;
11 - (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)object;
12 - (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index;
16 @interface NSMutableDictionary
18 - (void)setObject:(id)object forKey:(id)key;
19 - (void)setObject:(id)object forKeyedSubscript:(id)key;
20 - (void)setValue:(id)value forKey:(NSString *)key;
24 @interface NSMutableSet
26 - (void)addObject:(id)object;
30 @interface NSCountedSet : NSMutableSet
34 @interface NSMutableOrderedSet
36 - (void)addObject:(id)object;
37 - (void)insertObject:(id)object atIndex:(NSUInteger)index;
38 - (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index;
39 - (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)object;
40 - (void)setObject:(id)object atIndex:(NSUInteger)index;
44 @interface SelfRefClass
46 NSMutableArray *_array; // expected-note {{'_array' declared here}}
47 NSMutableDictionary *_dictionary; // expected-note {{'_dictionary' declared here}}
48 NSMutableSet *_set; // expected-note {{'_set' declared here}}
49 NSCountedSet *_countedSet; // expected-note {{'_countedSet' declared here}}
50 NSMutableOrderedSet *_orderedSet; // expected-note {{'_orderedSet' declared here}}
54 @implementation SelfRefClass
57 [_array addObject:_array]; // expected-warning {{adding '_array' to '_array' might cause circular dependency in container}}
58 [_dictionary setObject:_dictionary forKey:@"key"]; // expected-warning {{adding '_dictionary' to '_dictionary' might cause circular dependency in container}}
59 [_set addObject:_set]; // expected-warning {{adding '_set' to '_set' might cause circular dependency in container}}
60 [_countedSet addObject:_countedSet]; // expected-warning {{adding '_countedSet' to '_countedSet' might cause circular dependency in container}}
61 [_orderedSet addObject:_orderedSet]; // expected-warning {{adding '_orderedSet' to '_orderedSet' might cause circular dependency in container}}
64 - (void)checkNSMutableArray:(NSMutableArray *)a { // expected-note {{'a' declared here}}
65 [a addObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
68 - (void)checkNSMutableDictionary:(NSMutableDictionary *)d { // expected-note {{'d' declared here}}
69 [d setObject:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
72 - (void)checkNSMutableSet:(NSMutableSet *)s { // expected-note {{'s' declared here}}
73 [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
76 - (void)checkNSCountedSet:(NSCountedSet *)s { // expected-note {{'s' declared here}}
77 [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
80 - (void)checkNSMutableOrderedSet:(NSMutableOrderedSet *)s { // expected-note {{'s' declared here}}
81 [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
86 void checkNSMutableArrayParam(NSMutableArray *a) { // expected-note {{'a' declared here}}
87 [a addObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
90 void checkNSMutableDictionaryParam(NSMutableDictionary *d) { // expected-note {{'d' declared here}}
91 [d setObject:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
94 void checkNSMutableSetParam(NSMutableSet *s) { // expected-note {{'s' declared here}}
95 [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
98 void checkNSCountedSetParam(NSCountedSet *s) { // expected-note {{'s' declared here}}
99 [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
102 void checkNSMutableOrderedSetParam(NSMutableOrderedSet *s) { // expected-note {{'s' declared here}}
103 [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
106 void checkNSMutableArray(void) {
107 NSMutableArray *a = nil; // expected-note 5 {{'a' declared here}} 5
109 [a addObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
110 [a insertObject:a atIndex:0]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
111 [a replaceObjectAtIndex:0 withObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
112 [a setObject:a atIndexedSubscript:0]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
113 a[0] = a; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
116 void checkNSMutableDictionary(void) {
117 NSMutableDictionary *d = nil; // expected-note 4 {{'d' declared here}}
119 [d setObject:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
120 [d setObject:d forKeyedSubscript:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
121 [d setValue:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
122 d[@"key"] = d; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
125 void checkNSMutableSet(void) {
126 NSMutableSet *s = nil; // expected-note {{'s' declared here}}
128 [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
131 void checkNSCountedSet(void) {
132 NSCountedSet *s = nil; // expected-note {{'s' declared here}}
134 [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
137 void checkNSMutableOrderedSet(void) {
138 NSMutableOrderedSet *s = nil; // expected-note 5 {{'s' declared here}}
140 [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
141 [s insertObject:s atIndex:0]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
142 [s setObject:s atIndex:0]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
143 [s setObject:s atIndexedSubscript:0]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
144 [s replaceObjectAtIndex:0 withObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
149 @interface FootableSet : NSMutableSet
152 @implementation FootableSet
154 [super addObject:self]; // expected-warning {{adding 'self' to 'super' might cause circular dependency in container}}
155 [super addObject:nil]; // no-warning
156 [self addObject:self]; // expected-warning {{adding 'self' to 'self' might cause circular dependency in container}}
160 @interface FootableArray : NSMutableArray
163 @implementation FootableArray
165 [super addObject:self]; // expected-warning {{adding 'self' to 'super' might cause circular dependency in container}}
166 [super addObject:nil]; // no-warning
167 [self addObject:self]; // expected-warning {{adding 'self' to 'self' might cause circular dependency in container}}
171 @interface FootableDictionary : NSMutableDictionary
174 @implementation FootableDictionary
176 [super setObject:self forKey:@"key"]; // expected-warning {{adding 'self' to 'super' might cause circular dependency in container}}
177 [super setObject:nil forKey:@"key"]; // no-warning
178 [self setObject:self forKey:@"key"]; // expected-warning {{adding 'self' to 'self' might cause circular dependency in container}}
183 void subclassingNSMutableArray(void) {
184 FootableArray *a = nil; // expected-note 5 {{'a' declared here}} 5
186 [a addObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
187 [a insertObject:a atIndex:0]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
188 [a replaceObjectAtIndex:0 withObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
189 [a setObject:a atIndexedSubscript:0]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
190 a[0] = a; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
193 void subclassingNSMutableDictionary(void) {
194 FootableDictionary *d = nil; // expected-note 4 {{'d' declared here}}
196 [d setObject:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
197 [d setObject:d forKeyedSubscript:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
198 [d setValue:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
199 d[@"key"] = d; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
202 void subclassingNSMutableSet(void) {
203 FootableSet *s = nil; // expected-note {{'s' declared here}}
205 [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}