Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10.4 -verify -Wno-objc-root-class %s |
| 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -triple x86_64-apple-darwin10.4 -verify -Wno-objc-root-class %s |
Anders Carlsson | 59843ad | 2009-02-14 19:08:58 +0000 | [diff] [blame] | 3 | |
Chris Lattner | 553905d | 2009-02-16 17:19:12 +0000 | [diff] [blame] | 4 | @interface A { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 5 | int X __attribute__((deprecated)); // expected-note 2 {{'X' has been explicitly marked deprecated here}} |
Chris Lattner | 553905d | 2009-02-16 17:19:12 +0000 | [diff] [blame] | 6 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 7 | + (void)F __attribute__((deprecated)); // expected-note 2 {{'F' has been explicitly marked deprecated here}} |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 8 | - (void)f __attribute__((deprecated)); // expected-note 5 {{'f' has been explicitly marked deprecated here}} |
Anders Carlsson | 59843ad | 2009-02-14 19:08:58 +0000 | [diff] [blame] | 9 | @end |
| 10 | |
| 11 | @implementation A |
| 12 | + (void)F __attribute__((deprecated)) |
Fariborz Jahanian | 7fda400 | 2011-10-22 01:21:15 +0000 | [diff] [blame] | 13 | { |
Chris Lattner | b254ca0 | 2009-02-16 17:08:46 +0000 | [diff] [blame] | 14 | [self F]; // no warning, since the caller is also deprecated. |
Anders Carlsson | 59843ad | 2009-02-14 19:08:58 +0000 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | - (void)g |
| 18 | { |
Chris Lattner | 553905d | 2009-02-16 17:19:12 +0000 | [diff] [blame] | 19 | X++; // expected-warning{{'X' is deprecated}} |
| 20 | self->X++; // expected-warning{{'X' is deprecated}} |
Anders Carlsson | 59843ad | 2009-02-14 19:08:58 +0000 | [diff] [blame] | 21 | [self f]; // expected-warning{{'f' is deprecated}} |
| 22 | } |
| 23 | |
| 24 | - (void)f |
| 25 | { |
Chris Lattner | f15970c | 2009-02-16 19:35:30 +0000 | [diff] [blame] | 26 | [self f]; // no warning, the caller is deprecated in its interface. |
Anders Carlsson | 59843ad | 2009-02-14 19:08:58 +0000 | [diff] [blame] | 27 | } |
| 28 | @end |
| 29 | |
| 30 | @interface B: A |
| 31 | @end |
| 32 | |
| 33 | @implementation B |
| 34 | + (void)G |
| 35 | { |
| 36 | [super F]; // expected-warning{{'F' is deprecated}} |
| 37 | } |
| 38 | |
| 39 | - (void)g |
| 40 | { |
| 41 | [super f]; // // expected-warning{{'f' is deprecated}} |
| 42 | } |
| 43 | @end |
| 44 | |
| 45 | @protocol P |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 46 | - (void)p __attribute__((deprecated)); // expected-note {{'p' has been explicitly marked deprecated here}} |
Anders Carlsson | 59843ad | 2009-02-14 19:08:58 +0000 | [diff] [blame] | 47 | @end |
| 48 | |
| 49 | void t1(A *a) |
| 50 | { |
| 51 | [A F]; // expected-warning{{'F' is deprecated}} |
| 52 | [a f]; // expected-warning{{'f' is deprecated}} |
| 53 | } |
| 54 | |
| 55 | void t2(id a) |
| 56 | { |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 57 | [a f]; // expected-warning {{'f' is deprecated}} |
Anders Carlsson | 59843ad | 2009-02-14 19:08:58 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void t3(A<P>* a) |
| 61 | { |
| 62 | [a f]; // expected-warning{{'f' is deprecated}} |
| 63 | [a p]; // expected-warning{{'p' is deprecated}} |
| 64 | } |
| 65 | |
| 66 | void t4(Class c) |
| 67 | { |
| 68 | [c F]; |
| 69 | } |
| 70 | |
Chris Lattner | 7eba82e | 2009-02-16 18:35:08 +0000 | [diff] [blame] | 71 | |
| 72 | |
| 73 | @interface Bar |
| 74 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 75 | @property (assign, setter = MySetter:) int FooBar __attribute__ ((deprecated)); // expected-note 2 {{'FooBar' has been explicitly marked deprecated here}} |
Chris Lattner | 7eba82e | 2009-02-16 18:35:08 +0000 | [diff] [blame] | 76 | - (void) MySetter : (int) value; |
| 77 | @end |
| 78 | |
| 79 | int t5() { |
| 80 | Bar *f; |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 81 | f.FooBar = 1; // expected-warning {{'FooBar' is deprecated}} |
| 82 | return f.FooBar; // expected-warning {{'FooBar' is deprecated}} |
Chris Lattner | 7eba82e | 2009-02-16 18:35:08 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Chris Lattner | 16b34b4 | 2009-02-16 21:30:01 +0000 | [diff] [blame] | 85 | |
| 86 | __attribute ((deprecated)) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 87 | @interface DEPRECATED { // expected-note 2 {{'DEPRECATED' has been explicitly marked deprecated here}} |
Chris Lattner | 16b34b4 | 2009-02-16 21:30:01 +0000 | [diff] [blame] | 88 | @public int ivar; |
Argyrios Kyrtzidis | 3a38744 | 2011-10-06 23:23:20 +0000 | [diff] [blame] | 89 | DEPRECATED *ivar2; // no warning. |
Chris Lattner | 16b34b4 | 2009-02-16 21:30:01 +0000 | [diff] [blame] | 90 | } |
| 91 | - (int) instancemethod; |
Argyrios Kyrtzidis | 3a38744 | 2011-10-06 23:23:20 +0000 | [diff] [blame] | 92 | - (DEPRECATED *) meth; // no warning. |
Chris Lattner | 16b34b4 | 2009-02-16 21:30:01 +0000 | [diff] [blame] | 93 | @property int prop; |
| 94 | @end |
| 95 | |
Argyrios Kyrtzidis | c076e37 | 2011-10-06 23:23:27 +0000 | [diff] [blame] | 96 | @interface DEPRECATED (Category) // no warning. |
| 97 | - (DEPRECATED *) meth2; // no warning. |
| 98 | @end |
| 99 | |
| 100 | @interface DEPRECATED (Category2) // no warning. |
| 101 | @end |
| 102 | |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 103 | @implementation DEPRECATED (Category2) // expected-warning {{'DEPRECATED' is deprecated}} |
Chris Lattner | 16b34b4 | 2009-02-16 21:30:01 +0000 | [diff] [blame] | 104 | @end |
Chris Lattner | c7984dd | 2009-02-16 21:33:09 +0000 | [diff] [blame] | 105 | |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 106 | @interface NS : DEPRECATED // expected-warning {{'DEPRECATED' is deprecated}} |
Chris Lattner | c7984dd | 2009-02-16 21:33:09 +0000 | [diff] [blame] | 107 | @end |
| 108 | |
| 109 | |
John McCall | 5de74d1 | 2010-11-10 07:01:40 +0000 | [diff] [blame] | 110 | @interface Test2 |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 111 | @property int test2 __attribute__((deprecated)); // expected-note 2 {{property 'test2' is declared deprecated here}} expected-note 3 {{'test2' has been explicitly marked deprecated here}} \ |
| 112 | // expected-note {{'setTest2:' has been explicitly marked deprecated here}} |
John McCall | 5de74d1 | 2010-11-10 07:01:40 +0000 | [diff] [blame] | 113 | @end |
| 114 | |
| 115 | void test(Test2 *foo) { |
| 116 | int x; |
| 117 | x = foo.test2; // expected-warning {{'test2' is deprecated}} |
| 118 | x = [foo test2]; // expected-warning {{'test2' is deprecated}} |
| 119 | foo.test2 = x; // expected-warning {{'test2' is deprecated}} |
| 120 | [foo setTest2: x]; // expected-warning {{'setTest2:' is deprecated}} |
| 121 | } |
Douglas Gregor | 13d05ac | 2011-09-23 19:19:41 +0000 | [diff] [blame] | 122 | |
| 123 | __attribute__((deprecated)) |
| 124 | @interface A(Blah) // expected-error{{attributes may not be specified on a category}} |
| 125 | @end |
Eli Friedman | f66a0dd | 2012-08-08 23:04:35 +0000 | [diff] [blame] | 126 | |
| 127 | |
| 128 | typedef struct { |
| 129 | int x; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 130 | } footype __attribute((deprecated)); // expected-note 2 {{'footype' has been explicitly marked deprecated here}} |
Eli Friedman | f66a0dd | 2012-08-08 23:04:35 +0000 | [diff] [blame] | 131 | |
| 132 | @interface foo { |
| 133 | footype a; // expected-warning {{'footype' is deprecated}} |
| 134 | footype b __attribute((deprecated)); |
| 135 | } |
| 136 | @property footype c; // expected-warning {{'footype' is deprecated}} |
| 137 | @property footype d __attribute((deprecated)); |
| 138 | @end |
Fariborz Jahanian | 740991b | 2013-04-04 18:45:52 +0000 | [diff] [blame] | 139 | |
| 140 | // rdar://13569424 |
| 141 | @interface NewI |
| 142 | +(void)cmeth; |
| 143 | @end |
| 144 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 145 | typedef NewI DeprI __attribute__((deprecated("blah"))); // expected-note 4 {{'DeprI' has been explicitly marked deprecated here}} |
Fariborz Jahanian | 740991b | 2013-04-04 18:45:52 +0000 | [diff] [blame] | 146 | |
| 147 | @interface SI : DeprI // expected-warning {{'DeprI' is deprecated: blah}} |
| 148 | -(DeprI*)meth; // expected-warning {{'DeprI' is deprecated: blah}} |
| 149 | @end |
| 150 | |
| 151 | @implementation SI |
| 152 | -(DeprI*)meth { // expected-warning {{'DeprI' is deprecated: blah}} |
| 153 | [DeprI cmeth]; // expected-warning {{'DeprI' is deprecated: blah}} |
| 154 | return 0; |
| 155 | } |
| 156 | @end |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 157 | |
| 158 | // <rdar://problem/15407366> and <rdar://problem/15466783>: |
| 159 | // - Using deprecated class name inside class should not warn about deprecation. |
| 160 | // - Implementations of deprecated classes should not result in deprecation warnings. |
| 161 | __attribute__((deprecated)) |
| 162 | @interface DeprecatedClassA |
| 163 | @end |
| 164 | |
| 165 | __attribute__((deprecated)) |
| 166 | @interface DeprecatedClassB |
| 167 | // The self-reference return value should not be |
| 168 | // flagged as the use of a deprecated declaration. |
| 169 | + (DeprecatedClassB *)sharedInstance; // no-warning |
| 170 | |
| 171 | // Since this class is deprecated, returning a reference |
| 172 | // to another deprecated class is fine as they may |
| 173 | // have been deprecated together. From a user's |
| 174 | // perspective they are all deprecated. |
| 175 | + (DeprecatedClassA *)somethingElse; // no-warning |
| 176 | @end |
| 177 | |
| 178 | @implementation DeprecatedClassB |
| 179 | + (DeprecatedClassB *)sharedInstance |
| 180 | { |
| 181 | // This self-reference should not |
| 182 | // be flagged as a use of a deprecated |
| 183 | // declaration. |
| 184 | static DeprecatedClassB *x; // no-warning |
| 185 | return x; |
| 186 | } |
| 187 | + (DeprecatedClassA *)somethingElse { |
| 188 | // Since this class is deprecated, referencing |
| 189 | // another deprecated class is also OK. |
| 190 | static DeprecatedClassA *x; // no-warning |
| 191 | return x; |
| 192 | } |
| 193 | |
| 194 | @end |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 195 | |
| 196 | // rdar://16068470 |
| 197 | @interface TestBase |
| 198 | @property (nonatomic, strong) id object __attribute__((deprecated("deprecated"))); // expected-note {{'object' has been explicitly marked deprecated here}} \ |
| 199 | expected-note {{property 'object' is declared deprecated here}} \ |
| 200 | expected-note {{'setObject:' has been explicitly marked deprecated here}} \ |
| 201 | expected-note {{property declared here}} |
| 202 | @end |
| 203 | |
| 204 | @interface TestDerived : TestBase |
| 205 | @property (nonatomic, strong) id object; //expected-warning {{auto property synthesis will not synthesize property 'object'; it will be implemented by its superclass}} |
| 206 | @end |
| 207 | |
| 208 | @interface TestUse @end |
| 209 | |
| 210 | @implementation TestBase @end |
| 211 | |
| 212 | @implementation TestDerived @end // expected-note {{detected while default synthesizing properties in class implementation}} |
| 213 | |
| 214 | @implementation TestUse |
| 215 | |
| 216 | - (void) use |
| 217 | { |
| 218 | TestBase *base = (id)0; |
| 219 | TestDerived *derived = (id)0; |
| 220 | id object = (id)0; |
| 221 | |
| 222 | base.object = object; // expected-warning {{'object' is deprecated: deprecated}} |
| 223 | derived.object = object; |
| 224 | |
| 225 | [base setObject:object]; // expected-warning {{'setObject:' is deprecated: deprecated}} |
| 226 | [derived setObject:object]; |
| 227 | } |
| 228 | |
| 229 | @end |
| 230 | |
| 231 | // rdar://18848183 |
| 232 | @interface NSString |
| 233 | - (const char *)cString __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.4,message="" ))); // expected-note {{'cString' has been explicitly marked deprecated here}} |
| 234 | @end |
| 235 | |
| 236 | id PID = 0; |
| 237 | const char * func() { |
| 238 | return [PID cString]; // expected-warning {{'cString' is deprecated: first deprecated in OS X 10.4}} |
| 239 | } |
| 240 | |
| 241 | // rdar://18960378 |
| 242 | @interface NSObject |
| 243 | + (instancetype)alloc; |
| 244 | - (instancetype)init; |
| 245 | @end |
| 246 | |
| 247 | @interface NSLocale |
| 248 | - (instancetype)init __attribute__((unavailable)); |
| 249 | @end |
| 250 | |
| 251 | @interface PLBatteryProperties : NSObject |
| 252 | + (id)properties; |
| 253 | @end |
| 254 | |
| 255 | @implementation PLBatteryProperties |
| 256 | + (id)properties { |
| 257 | return [[self alloc] init]; |
| 258 | } |
| 259 | @end |
| 260 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 261 | @implementation UndeclaredImpl // expected-warning{{cannot find interface declaration}} |
| 262 | - (void)partiallyUnavailableMethod {} |
| 263 | @end |
| 264 | |
| 265 | @interface InterfaceWithSameMethodAsUndeclaredImpl |
| 266 | - (void)partiallyUnavailableMethod __attribute__((unavailable)); |
| 267 | @end |
| 268 | |
| 269 | void f(id a) { |
| 270 | [a partiallyUnavailableMethod]; // no warning, `a` could be an UndeclaredImpl. |
| 271 | } |
| 272 | |
| 273 | @interface InterfaceWithImplementation |
| 274 | - (void)anotherPartiallyUnavailableMethod; |
| 275 | @end |
| 276 | @implementation InterfaceWithImplementation |
| 277 | - (void)anotherPartiallyUnavailableMethod {} |
| 278 | @end |
| 279 | |
| 280 | @interface InterfaceWithSameMethodAsInterfaceWithImplementation |
| 281 | - (void)anotherPartiallyUnavailableMethod __attribute__((unavailable)); |
| 282 | @end |
| 283 | |
| 284 | void g(id a) { |
| 285 | [a anotherPartiallyUnavailableMethod]; // no warning, `a` could be an InterfaceWithImplementation. |
| 286 | } |
| 287 | |
| 288 | typedef struct {} S1 __attribute__((unavailable)); // expected-note2{{marked unavailable here}} |
| 289 | typedef struct {} S2 __attribute__((deprecated)); // expected-note2{{marked deprecated here}} |
| 290 | @interface ExtensionForMissingInterface() // expected-error{{cannot find interface declaration}} |
| 291 | - (void)method1:(S1) x; // expected-error{{is unavailable}} |
| 292 | - (void)method2:(S2) x; // expected-warning{{is deprecated}} |
| 293 | @end |
| 294 | @interface CategoryForMissingInterface(Cat) // expected-error{{cannot find interface declaration}} |
| 295 | - (void)method1:(S1) x; // expected-error{{is unavailable}} |
| 296 | - (void)method2:(S2) x; // expected-warning{{is deprecated}} |
| 297 | @end |