[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / clang / test / SemaObjC / attr-deprecated.m
blob28031997af7a9164f45ac66437f8199daa67a30b
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
4 @interface A {
5   int X __attribute__((deprecated)); // expected-note 2 {{'X' has been explicitly marked deprecated here}}
7 + (void)F __attribute__((deprecated)); // expected-note 2 {{'F' has been explicitly marked deprecated here}}
8 - (void)f __attribute__((deprecated)); // expected-note 5 {{'f' has been explicitly marked deprecated here}}
9 @end
11 @implementation A
12 + (void)F __attribute__((deprecated))
14   [self F]; // no warning, since the caller is also deprecated.
17 - (void)g
19   X++;        // expected-warning{{'X' is deprecated}}
20   self->X++;  // expected-warning{{'X' is deprecated}}
21   [self f]; // expected-warning{{'f' is deprecated}}
24 - (void)f
26   [self f]; // no warning, the caller is deprecated in its interface.
28 @end
30 @interface B: A
31 @end
32   
33 @implementation B
34 + (void)G
36   [super F]; // expected-warning{{'F' is deprecated}}
39 - (void)g
41   [super f]; // // expected-warning{{'f' is deprecated}}
43 @end
45 @protocol P
46 - (void)p __attribute__((deprecated)); // expected-note {{'p' has been explicitly marked deprecated here}}
47 @end
49 void t1(A *a)
51   [A F]; // expected-warning{{'F' is deprecated}}
52   [a f]; // expected-warning{{'f' is deprecated}}
55 void t2(id a)
57   [a f]; // expected-warning {{'f' is deprecated}}
60 void t3(A<P>* a)
62   [a f]; // expected-warning{{'f' is deprecated}}
63   [a p]; // expected-warning{{'p' is deprecated}}
64
66 void t4(Class c)
68   [c F];
73 @interface Bar 
75 @property (assign, setter = MySetter:) int FooBar __attribute__ ((deprecated)); // expected-note 2 {{'FooBar' has been explicitly marked deprecated here}}
76 - (void) MySetter : (int) value;
77 @end
79 int t5() {
80   Bar *f;
81   f.FooBar = 1;    // expected-warning {{'FooBar' is deprecated}}
82   return f.FooBar; // expected-warning {{'FooBar' is deprecated}}
86 __attribute ((deprecated)) // expected-note {{'DEPRECATED' has been explicitly marked deprecated here}}
87 @interface DEPRECATED { 
88   @public int ivar; 
89   DEPRECATED *ivar2; // no warning.
90
91 - (int) instancemethod;
92 - (DEPRECATED *) meth; // no warning.
93 @property  int prop; 
94 @end
96 @interface DEPRECATED (Category) // no warning.
97 - (DEPRECATED *) meth2; // no warning.
98 @end
100 @interface DEPRECATED (Category2) // no warning.
101 - (id)meth;
102 @end
104 __attribute__((deprecated))
105 void depr_function();
107 @implementation DEPRECATED (Category2) // no warning
108 - (id)meth {
109   depr_function(); // no warning.
110   return 0;
112 @end
114 @interface NS : DEPRECATED  // expected-warning {{'DEPRECATED' is deprecated}}
115 @end
118 @interface Test2
119 @property int test2 __attribute__((deprecated)); // expected-note 2 {{property 'test2' is declared deprecated here}} expected-note 3 {{'test2' has been explicitly marked deprecated here}} \
120                                                  // expected-note {{'setTest2:' has been explicitly marked deprecated here}}
121 @end
123 void test(Test2 *foo) {
124   int x;
125   x = foo.test2; // expected-warning {{'test2' is deprecated}}
126   x = [foo test2]; // expected-warning {{'test2' is deprecated}}
127   foo.test2 = x; // expected-warning {{'test2' is deprecated}}
128   [foo setTest2: x]; // expected-warning {{'setTest2:' is deprecated}}
131 __attribute__((deprecated))
132 @interface A(Blah) // no warning
133 - (A*)getA;
134 @end
136 @implementation A(Blah) // Don't warn by default
137 - (A*)getA {
138   return self;
140 @end
142 typedef struct {
143         int x;
144 } footype __attribute((deprecated)); // expected-note 2 {{'footype' has been explicitly marked deprecated here}}
146 @interface foo {
147         footype a; // expected-warning {{'footype' is deprecated}}
148         footype b __attribute((deprecated));
150 @property footype c; // expected-warning {{'footype' is deprecated}}
151 @property footype d __attribute((deprecated));
152 @end
154 // rdar://13569424
155 @interface NewI
156 +(void)cmeth;
157 @end
159 typedef NewI DeprI __attribute__((deprecated("blah"))); // expected-note 4 {{'DeprI' has been explicitly marked deprecated here}}
161 @interface SI : DeprI // expected-warning {{'DeprI' is deprecated: blah}}
162 -(DeprI*)meth; // expected-warning {{'DeprI' is deprecated: blah}}
163 @end
165 @implementation SI
166 -(DeprI*)meth { // expected-warning {{'DeprI' is deprecated: blah}}
167   [DeprI cmeth]; // expected-warning {{'DeprI' is deprecated: blah}}
168   return 0;
170 @end
172 // <rdar://problem/15407366> and <rdar://problem/15466783>:
173 // - Using deprecated class name inside class should not warn about deprecation.
174 // - Implementations of deprecated classes should not result in deprecation warnings.
175 __attribute__((deprecated))
176 @interface DeprecatedClassA
177 @end
179 __attribute__((deprecated))
180 @interface DeprecatedClassB
181 // The self-reference return value should not be
182 // flagged as the use of a deprecated declaration.
183 + (DeprecatedClassB *)sharedInstance; // no-warning
185 // Since this class is deprecated, returning a reference
186 // to another deprecated class is fine as they may
187 // have been deprecated together.  From a user's
188 // perspective they are all deprecated.
189 + (DeprecatedClassA *)somethingElse; // no-warning
190 @end
192 @implementation DeprecatedClassB
193 + (DeprecatedClassB *)sharedInstance
195   // This self-reference should not
196   // be flagged as a use of a deprecated
197   // declaration.
198   static DeprecatedClassB *x; // no-warning
199   return x;
201 + (DeprecatedClassA *)somethingElse {
202   // Since this class is deprecated, referencing
203   // another deprecated class is also OK.
204   static DeprecatedClassA *x; // no-warning
205   return x;
208 @end
210 // rdar://16068470
211 @interface TestBase
212 @property (nonatomic, strong) id object __attribute__((deprecated("deprecated"))); // expected-note {{'object' has been explicitly marked deprecated here}} \
213 expected-note {{property 'object' is declared deprecated here}} \
214 expected-note {{'setObject:' has been explicitly marked deprecated here}} \
215 expected-note {{property declared here}}
216 @end
218 @interface TestDerived : TestBase
219 @property (nonatomic, strong) id object; //expected-warning {{auto property synthesis will not synthesize property 'object'; it will be implemented by its superclass}}
220 @end
222 @interface TestUse @end
224 @implementation TestBase @end
226 @implementation TestDerived @end // expected-note {{detected while default synthesizing properties in class implementation}}
228 @implementation TestUse
230 - (void) use
232     TestBase *base = (id)0;
233     TestDerived *derived = (id)0;
234     id object = (id)0;
236     base.object = object; // expected-warning {{'object' is deprecated: deprecated}}
237     derived.object = object;
239     [base setObject:object];  // expected-warning {{'setObject:' is deprecated: deprecated}}
240     [derived setObject:object];
243 @end
245 // rdar://18848183
246 @interface NSString
247 - (const char *)cString __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.4,message="" ))); // expected-note {{'cString' has been explicitly marked deprecated here}}
248 @end
250 id PID = 0;
251 const char * func() {
252   return [PID cString]; // expected-warning {{'cString' is deprecated: first deprecated in macOS 10.4}}
255 // rdar://18960378
256 @interface NSObject
257 + (instancetype)alloc;
258 - (instancetype)init;
259 @end
261 @interface NSLocale
262 - (instancetype)init __attribute__((unavailable));
263 @end
265 @interface PLBatteryProperties : NSObject
266 + (id)properties;
267 @end
269 @implementation PLBatteryProperties
270 + (id)properties {
271     return [[self alloc] init];
273 @end
275 @implementation UndeclaredImpl // expected-warning{{cannot find interface declaration}}
276 - (void)partiallyUnavailableMethod {}
277 @end
279 @interface InterfaceWithSameMethodAsUndeclaredImpl
280 - (void)partiallyUnavailableMethod __attribute__((unavailable));
281 @end
283 void f(id a) {
284   [a partiallyUnavailableMethod]; // no warning, `a` could be an UndeclaredImpl.
287 @interface InterfaceWithImplementation
288 - (void)anotherPartiallyUnavailableMethod;
289 @end
290 @implementation InterfaceWithImplementation
291 - (void)anotherPartiallyUnavailableMethod {}
292 @end
294 @interface InterfaceWithSameMethodAsInterfaceWithImplementation
295 - (void)anotherPartiallyUnavailableMethod __attribute__((unavailable));
296 @end
298 void g(id a) {
299   [a anotherPartiallyUnavailableMethod]; // no warning, `a` could be an InterfaceWithImplementation.
302 typedef struct {} S1 __attribute__((unavailable)); // expected-note2{{marked unavailable here}}
303 typedef struct {} S2 __attribute__((deprecated)); // expected-note2{{marked deprecated here}}
304 @interface ExtensionForMissingInterface() // expected-error{{cannot find interface declaration}}
305 - (void)method1:(S1) x; // expected-error{{is unavailable}}
306 - (void)method2:(S2) x; // expected-warning{{is deprecated}}
307 @end
308 @interface CategoryForMissingInterface(Cat) // expected-error{{cannot find interface declaration}}
309 - (void)method1:(S1) x; // expected-error{{is unavailable}}
310 - (void)method2:(S2) x; // expected-warning{{is deprecated}}
311 @end