]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaObjC/circular-container.m
Vendor import of clang trunk r238337:
[FreeBSD/FreeBSD.git] / test / SemaObjC / circular-container.m
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
2
3 typedef long int NSUInteger;
4 #define nil 0
5 @class NSString;
6
7 @interface NSMutableArray
8
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;
13
14 @end
15
16 @interface NSMutableDictionary
17
18 - (void)setObject:(id)object forKey:(id)key;
19 - (void)setObject:(id)object forKeyedSubscript:(id)key;
20 - (void)setValue:(id)value forKey:(NSString *)key;
21
22 @end
23
24 @interface NSMutableSet
25
26 - (void)addObject:(id)object;
27
28 @end
29
30 @interface NSCountedSet : NSMutableSet
31
32 @end
33
34 @interface NSMutableOrderedSet
35
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;
41
42 @end
43
44 @interface SelfRefClass
45 {
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}}
51 }
52 @end
53
54 @implementation SelfRefClass
55
56 - (void)check {
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}}
62 }
63
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}}
66 }
67
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}}
70 }
71
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}}
74 }
75
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}}
78 }
79
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}}
82 }
83
84 @end
85
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}}
88 }
89
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}}
92 }
93
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}}
96 }
97
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}}
100 }
101
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}}
104 }
105
106 void checkNSMutableArray() {
107   NSMutableArray *a = nil; // expected-note 5 {{'a' declared here}} 5
108
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}}
114 }
115
116 void checkNSMutableDictionary() {
117   NSMutableDictionary *d = nil; // expected-note 4 {{'d' declared here}}
118
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}}
123 }
124
125 void checkNSMutableSet() {
126   NSMutableSet *s = nil; // expected-note {{'s' declared here}}
127
128   [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
129 }
130
131 void checkNSCountedSet() {
132   NSCountedSet *s = nil; // expected-note {{'s' declared here}}
133
134   [s addObject:s]; // expected-warning {{adding 's' to 's' might cause circular dependency in container}}
135 }
136
137 void checkNSMutableOrderedSet() {
138   NSMutableOrderedSet *s = nil; // expected-note 5 {{'s' declared here}}
139
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}}
145 }
146