reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s

typedef long int NSUInteger;
#define nil 0
@class NSString;

@interface NSMutableArray

- (void)addObject:(id)object;
- (void)insertObject:(id)object atIndex:(NSUInteger)index;
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)object;
- (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index;

@end

@interface NSMutableDictionary

- (void)setObject:(id)object forKey:(id)key;
- (void)setObject:(id)object forKeyedSubscript:(id)key;
- (void)setValue:(id)value forKey:(NSString *)key;

@end

@interface NSMutableSet

- (void)addObject:(id)object;

@end

@interface NSCountedSet : NSMutableSet

@end

@interface NSMutableOrderedSet

- (void)addObject:(id)object;
- (void)insertObject:(id)object atIndex:(NSUInteger)index;
- (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index;
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)object;
- (void)setObject:(id)object atIndex:(NSUInteger)index;

@end

@interface SelfRefClass
{
  NSMutableArray *_array; // expected-note {{'_array' declared here}}
  NSMutableDictionary *_dictionary; // expected-note {{'_dictionary' declared here}}
  NSMutableSet *_set; // expected-note {{'_set' declared here}}
  NSCountedSet *_countedSet; // expected-note {{'_countedSet' declared here}}
  NSMutableOrderedSet *_orderedSet; // expected-note {{'_orderedSet' declared here}}
}
@end

@implementation SelfRefClass

- (void)check {
  [_array addObject:_array]; // expected-warning {{adding '_array' to '_array' might cause circular dependency in container}}
  [_dictionary setObject:_dictionary forKey:@"key"]; // expected-warning {{adding '_dictionary' to '_dictionary' might cause circular dependency in container}}
  [_set addObject:_set]; // expected-warning {{adding '_set' to '_set' might cause circular dependency in container}}
  [_countedSet addObject:_countedSet]; // expected-warning {{adding '_countedSet' to '_countedSet' might cause circular dependency in container}}
  [_orderedSet addObject:_orderedSet]; // expected-warning {{adding '_orderedSet' to '_orderedSet' might cause circular dependency in container}}
}

- (void)checkNSMutableArray:(NSMutableArray *)a { // expected-note {{'a' declared here}}
  [a addObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
}

- (void)checkNSMutableDictionary:(NSMutableDictionary *)d { // expected-note {{'d' declared here}}
  [d setObject:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
}

- (void)checkNSMutableSet:(NSMutableSet *)s { // expected-note {{'s' declared here}}
  [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
}

- (void)checkNSCountedSet:(NSCountedSet *)s { // expected-note {{'s' declared here}}
  [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
}

- (void)checkNSMutableOrderedSet:(NSMutableOrderedSet *)s { // expected-note {{'s' declared here}}
  [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
}

@end

void checkNSMutableArrayParam(NSMutableArray *a) { // expected-note {{'a' declared here}}
  [a addObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
}

void checkNSMutableDictionaryParam(NSMutableDictionary *d) { // expected-note {{'d' declared here}}
  [d setObject:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
}

void checkNSMutableSetParam(NSMutableSet *s) { // expected-note {{'s' declared here}}
  [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
}

void checkNSCountedSetParam(NSCountedSet *s) { // expected-note {{'s' declared here}}
  [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
}

void checkNSMutableOrderedSetParam(NSMutableOrderedSet *s) { // expected-note {{'s' declared here}}
  [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
}

void checkNSMutableArray() {
  NSMutableArray *a = nil; // expected-note 5 {{'a' declared here}} 5

  [a addObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
  [a insertObject:a atIndex:0]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
  [a replaceObjectAtIndex:0 withObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
  [a setObject:a atIndexedSubscript:0]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
  a[0] = a; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
}

void checkNSMutableDictionary() {
  NSMutableDictionary *d = nil; // expected-note 4 {{'d' declared here}}

  [d setObject:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
  [d setObject:d forKeyedSubscript:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
  [d setValue:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
  d[@"key"] = d; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
}

void checkNSMutableSet() {
  NSMutableSet *s = nil; // expected-note {{'s' declared here}}

  [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
}

void checkNSCountedSet() {
  NSCountedSet *s = nil; // expected-note {{'s' declared here}}

  [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
}

void checkNSMutableOrderedSet() {
  NSMutableOrderedSet *s = nil; // expected-note 5 {{'s' declared here}}

  [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
  [s insertObject:s atIndex:0]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
  [s setObject:s atIndex:0]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
  [s setObject:s atIndexedSubscript:0]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
  [s replaceObjectAtIndex:0 withObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
}

// Test subclassing

@interface FootableSet : NSMutableSet
@end

@implementation FootableSet
- (void)meth {
  [super addObject:self]; // expected-warning {{adding 'self' to 'super' might cause circular dependency in container}}
  [super addObject:nil]; // no-warning
  [self addObject:self]; // expected-warning {{adding 'self' to 'self' might cause circular dependency in container}}
}
@end

@interface FootableArray : NSMutableArray
@end

@implementation FootableArray
- (void)meth {
  [super addObject:self]; // expected-warning {{adding 'self' to 'super' might cause circular dependency in container}}
  [super addObject:nil]; // no-warning
  [self addObject:self]; // expected-warning {{adding 'self' to 'self' might cause circular dependency in container}}
}
@end

@interface FootableDictionary : NSMutableDictionary
@end

@implementation FootableDictionary
- (void)meth {
  [super setObject:self forKey:@"key"]; // expected-warning {{adding 'self' to 'super' might cause circular dependency in container}}
  [super setObject:nil forKey:@"key"]; // no-warning
  [self setObject:self forKey:@"key"]; // expected-warning {{adding 'self' to 'self' might cause circular dependency in container}}
}
@end


void subclassingNSMutableArray() {
  FootableArray *a = nil; // expected-note 5 {{'a' declared here}} 5

  [a addObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
  [a insertObject:a atIndex:0]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
  [a replaceObjectAtIndex:0 withObject:a]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
  [a setObject:a atIndexedSubscript:0]; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
  a[0] = a; // expected-warning {{adding 'a' to 'a' might cause circular dependency in container}}
}

void subclassingNSMutableDictionary() {
  FootableDictionary *d = nil; // expected-note 4 {{'d' declared here}}

  [d setObject:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
  [d setObject:d forKeyedSubscript:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
  [d setValue:d forKey:@"key"]; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
  d[@"key"] = d; // expected-warning {{adding 'd' to 'd' might cause circular dependency in container}}
}

void subclassingNSMutableSet() {
  FootableSet *s = nil; // expected-note {{'s' declared here}}

  [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
}