blob: 8cf4f9731bc47e70954237201df764fe44c218f0 [file] [log] [blame]
Fariborz Jahanian974c9482012-09-21 20:46:37 +00001// RUN: %clang_cc1 -fsyntax-only -triple thumbv6-apple-ios3.0 -verify -Wno-objc-root-class %s
Nico Weber0055a192015-03-19 19:18:22 +00002// RUN: %clang_cc1 -D WARN_PARTIAL -Wpartial-availability -fsyntax-only -triple thumbv6-apple-ios3.0 -verify -Wno-objc-root-class %s
Fariborz Jahanian974c9482012-09-21 20:46:37 +00003// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -triple thumbv6-apple-ios3.0 -verify -Wno-objc-root-class %s
4// rdar://12324295
5
Jordan Rose79af9852012-10-10 16:42:38 +00006typedef signed char BOOL;
7
Fariborz Jahanian974c9482012-09-21 20:46:37 +00008@protocol P
Ted Kremenekb79ee572013-12-18 23:30:06 +00009@property(nonatomic,assign) id ptarget __attribute__((availability(ios,introduced=2.0,deprecated=3.0))); // expected-note {{property 'ptarget' is declared deprecated here}} expected-note {{'ptarget' has been explicitly marked deprecated here}}
Nico Weber0055a192015-03-19 19:18:22 +000010
11#if defined(WARN_PARTIAL)
Erik Pilkington5cd57172016-08-16 17:44:11 +000012// expected-note@+2 {{'partialPtarget' has been explicitly marked partial here}}
Nico Weber0055a192015-03-19 19:18:22 +000013#endif
14@property(nonatomic,assign) id partialPtarget __attribute__((availability(ios,introduced=5.0)));
Fariborz Jahanian974c9482012-09-21 20:46:37 +000015@end
16
17@protocol P1<P>
Ted Kremenekb5445722013-04-06 00:34:27 +000018- (void)setPtarget:(id)arg;
Nico Weber0055a192015-03-19 19:18:22 +000019- (void)setPartialPtarget:(id)arg;
Fariborz Jahanian974c9482012-09-21 20:46:37 +000020@end
21
22
23@interface UITableViewCell<P1>
Ted Kremenekb79ee572013-12-18 23:30:06 +000024@property(nonatomic,assign) id target __attribute__((availability(ios,introduced=2.0,deprecated=3.0))); // expected-note {{property 'target' is declared deprecated here}} expected-note {{'setTarget:' has been explicitly marked deprecated here}}
Nico Weber0055a192015-03-19 19:18:22 +000025
26#if defined(WARN_PARTIAL)
Erik Pilkington5cd57172016-08-16 17:44:11 +000027// expected-note@+2 {{'setPartialTarget:' has been explicitly marked partial here}}
Nico Weber0055a192015-03-19 19:18:22 +000028#endif
29@property(nonatomic,assign) id partialTarget __attribute__((availability(ios,introduced=5.0)));
Fariborz Jahanian974c9482012-09-21 20:46:37 +000030@end
31
32@interface PSTableCell : UITableViewCell
Ted Kremenekb5445722013-04-06 00:34:27 +000033 - (void)setTarget:(id)target;
Nico Weber0055a192015-03-19 19:18:22 +000034 - (void)setPartialTarget:(id)target;
Fariborz Jahanian974c9482012-09-21 20:46:37 +000035@end
36
37@interface UITableViewCell(UIDeprecated)
Ted Kremenekb79ee572013-12-18 23:30:06 +000038@property(nonatomic,assign) id dep_target __attribute__((availability(ios,introduced=2.0,deprecated=3.0))); // expected-note 2 {{'dep_target' has been explicitly marked deprecated here}} \
Ted Kremenekb5445722013-04-06 00:34:27 +000039 // expected-note 4 {{property 'dep_target' is declared deprecated here}} \
Ted Kremenekb79ee572013-12-18 23:30:06 +000040 // expected-note 2 {{'setDep_target:' has been explicitly marked deprecated here}}
Nico Weber0055a192015-03-19 19:18:22 +000041
42#if defined(WARN_PARTIAL)
Erik Pilkington5cd57172016-08-16 17:44:11 +000043// expected-note@+2 2 {{'partial_dep_target' has been explicitly marked partial here}} expected-note@+2 2 {{'setPartial_dep_target:' has been explicitly marked partial here}}
Nico Weber0055a192015-03-19 19:18:22 +000044#endif
45@property(nonatomic,assign) id partial_dep_target __attribute__((availability(ios,introduced=5.0)));
Fariborz Jahanian974c9482012-09-21 20:46:37 +000046@end
47
48@implementation PSTableCell
49- (void)setTarget:(id)target {};
Nico Weber0055a192015-03-19 19:18:22 +000050- (void)setPartialTarget:(id)target {};
Fariborz Jahanian974c9482012-09-21 20:46:37 +000051- (void)setPtarget:(id)val {};
52- (void) Meth {
Ted Kremenekb5445722013-04-06 00:34:27 +000053 [self setTarget: (id)0]; // no-warning
54 [self setDep_target: [self dep_target]]; // expected-warning {{'dep_target' is deprecated: first deprecated in iOS 3.0}} \
55 // expected-warning {{'setDep_target:' is deprecated: first deprecated in iOS 3.0}}
56
57 [self setPtarget: (id)0]; // no-warning
Nico Weber0055a192015-03-19 19:18:22 +000058 [self setPartialTarget: (id)0]; // no-warning
59#if defined(WARN_PARTIAL)
Erik Pilkington5cd57172016-08-16 17:44:11 +000060 // expected-warning@+2 {{'partial_dep_target' is only available on iOS 5.0 or newer}} expected-warning@+2 {{'setPartial_dep_target:' is only available on iOS 5.0 or newer}} expected-note@+2 {{enclose 'partial_dep_target' in an @available check to silence this warning}} expected-note@+2 {{enclose 'setPartial_dep_target:' in an @available check to silence this warning}}
Nico Weber0055a192015-03-19 19:18:22 +000061#endif
62 [self setPartial_dep_target: [self partial_dep_target]];
63
64 [self setPartialPtarget: (id)0]; // no-warning
Ted Kremenekb5445722013-04-06 00:34:27 +000065}
66@end
67
68@implementation UITableViewCell
69@synthesize target;
Nico Weber0055a192015-03-19 19:18:22 +000070@synthesize partialTarget;
Ted Kremenekb5445722013-04-06 00:34:27 +000071@synthesize ptarget;
Nico Weber0055a192015-03-19 19:18:22 +000072@synthesize partialPtarget;
Ted Kremenekb5445722013-04-06 00:34:27 +000073- (void)setPtarget:(id)val {};
Nico Weber0055a192015-03-19 19:18:22 +000074- (void)setPartialPtarget:(id)val {};
Ted Kremenekb5445722013-04-06 00:34:27 +000075- (void)setTarget:(id)target {};
Nico Weber0055a192015-03-19 19:18:22 +000076- (void)setPartialTarget:(id)target {};
Ted Kremenekb5445722013-04-06 00:34:27 +000077- (void) Meth {
Fariborz Jahanian974c9482012-09-21 20:46:37 +000078 [self setTarget: (id)0]; // expected-warning {{'setTarget:' is deprecated: first deprecated in iOS 3.0}}
79 [self setDep_target: [self dep_target]]; // expected-warning {{'dep_target' is deprecated: first deprecated in iOS 3.0}} \
80 // expected-warning {{'setDep_target:' is deprecated: first deprecated in iOS 3.0}}
Nico Weber0055a192015-03-19 19:18:22 +000081
Ted Kremenekb5445722013-04-06 00:34:27 +000082 [self setPtarget: (id)0]; // no-warning
Nico Weber0055a192015-03-19 19:18:22 +000083
84#if defined(WARN_PARTIAL)
Erik Pilkington5cd57172016-08-16 17:44:11 +000085 // expected-warning@+2 {{'setPartialTarget:' is only available on iOS 5.0 or newer}} expected-note@+2 {{enclose 'setPartialTarget:' in an @available check to silence this warning}}
Nico Weber0055a192015-03-19 19:18:22 +000086#endif
87 [self setPartialTarget: (id)0];
88#if defined(WARN_PARTIAL)
Erik Pilkington5cd57172016-08-16 17:44:11 +000089 // expected-warning@+2 {{'partial_dep_target' is only available on iOS 5.0 or newer}} expected-warning@+2 {{'setPartial_dep_target:' is only available on iOS 5.0 or newer}} expected-note@+2 {{enclose 'partial_dep_target' in an @available check to silence this warning}} expected-note@+2 {{enclose 'setPartial_dep_target:' in an @available check to silence this warning}}
Nico Weber0055a192015-03-19 19:18:22 +000090#endif
91 [self setPartial_dep_target: [self partial_dep_target]];
92 [self setPartialPtarget: (id)0]; // no-warning
Fariborz Jahanian974c9482012-09-21 20:46:37 +000093}
94@end
Jordan Rose79af9852012-10-10 16:42:38 +000095
96
97@interface CustomAccessorNames
Ted Kremenekb79ee572013-12-18 23:30:06 +000098@property(getter=isEnabled,assign) BOOL enabled __attribute__((availability(ios,introduced=2.0,deprecated=3.0))); // expected-note {{'isEnabled' has been explicitly marked deprecated here}} expected-note {{property 'enabled' is declared deprecated here}}
Jordan Rose79af9852012-10-10 16:42:38 +000099
Ted Kremenekb79ee572013-12-18 23:30:06 +0000100@property(setter=setNewDelegate:,assign) id delegate __attribute__((availability(ios,introduced=2.0,deprecated=3.0))); // expected-note {{'setNewDelegate:' has been explicitly marked deprecated here}} expected-note {{property 'delegate' is declared deprecated here}}
Nico Weber0055a192015-03-19 19:18:22 +0000101
102#if defined(WARN_PARTIAL)
Erik Pilkington5cd57172016-08-16 17:44:11 +0000103// expected-note@+2 {{'partialIsEnabled' has been explicitly marked partial here}}
Nico Weber0055a192015-03-19 19:18:22 +0000104#endif
105@property(getter=partialIsEnabled,assign) BOOL partialEnabled __attribute__((availability(ios,introduced=5.0)));
106
107#if defined(WARN_PARTIAL)
Erik Pilkington5cd57172016-08-16 17:44:11 +0000108// expected-note@+2 {{'partialSetNewDelegate:' has been explicitly marked partial here}}
Nico Weber0055a192015-03-19 19:18:22 +0000109#endif
110@property(setter=partialSetNewDelegate:,assign) id partialDelegate __attribute__((availability(ios,introduced=5.0)));
Jordan Rose79af9852012-10-10 16:42:38 +0000111@end
112
113void testCustomAccessorNames(CustomAccessorNames *obj) {
114 if ([obj isEnabled]) // expected-warning {{'isEnabled' is deprecated: first deprecated in iOS 3.0}}
115 [obj setNewDelegate:0]; // expected-warning {{'setNewDelegate:' is deprecated: first deprecated in iOS 3.0}}
Nico Weber0055a192015-03-19 19:18:22 +0000116
117#if defined(WARN_PARTIAL)
Erik Pilkington5cd57172016-08-16 17:44:11 +0000118 // expected-warning@+2 {{'partialIsEnabled' is only available on iOS 5.0 or newer}} expected-warning@+3 {{'partialSetNewDelegate:' is only available on iOS 5.0 or newer}} expected-note@+2 {{enclose 'partialIsEnabled' in an @available check to silence this warning}} expected-note@+3 {{enclose 'partialSetNewDelegate:' in an @available check to silence this warning}}
Nico Weber0055a192015-03-19 19:18:22 +0000119#endif
120 if ([obj partialIsEnabled])
121 [obj partialSetNewDelegate:0];
Jordan Rose79af9852012-10-10 16:42:38 +0000122}
Jordan Rose2bd991a2012-10-10 16:42:54 +0000123
124
125@interface ProtocolInCategory
126@end
127
128@interface ProtocolInCategory (TheCategory) <P1>
Ted Kremenekb5445722013-04-06 00:34:27 +0000129- (id)ptarget;
Nico Weber0055a192015-03-19 19:18:22 +0000130- (id)partialPtarget;
Jordan Rose2bd991a2012-10-10 16:42:54 +0000131@end
132
Ted Kremenekb5445722013-04-06 00:34:27 +0000133id useDeprecatedProperty(ProtocolInCategory *obj, id<P> obj2, int flag) {
134 if (flag)
135 return [obj ptarget]; // no-warning
136 return [obj2 ptarget]; // expected-warning {{'ptarget' is deprecated: first deprecated in iOS 3.0}}
Nico Weber0055a192015-03-19 19:18:22 +0000137
138 if (flag)
139 return [obj partialPtarget]; // no-warning
140#if defined(WARN_PARTIAL)
Erik Pilkington5cd57172016-08-16 17:44:11 +0000141// expected-warning@+2 {{'partialPtarget' is only available on iOS 5.0 or newer}} expected-note@+2 {{enclose 'partialPtarget' in an @available check to silence this warning}}
Nico Weber0055a192015-03-19 19:18:22 +0000142#endif
143 return [obj2 partialPtarget];
Jordan Rose2bd991a2012-10-10 16:42:54 +0000144}
Fariborz Jahanian89ea9612014-06-16 17:25:41 +0000145
146// rdar://15951801
147@interface Foo
148{
149 int _x;
150}
151@property(nonatomic,readonly) int x;
152- (void)setX:(int)x __attribute__ ((deprecated)); // expected-note 2 {{'setX:' has been explicitly marked deprecated here}}
153- (int)x __attribute__ ((unavailable)); // expected-note {{'x' has been explicitly marked unavailable here}}
154@end
155
156@implementation Foo
157- (void)setX:(int)x {
158 _x = x;
159}
160- (int)x {
161 return _x;
162}
163@end
164
165void testUserAccessorAttributes(Foo *foo) {
166 [foo setX:5678]; // expected-warning {{'setX:' is deprecated}}
167 foo.x = foo.x; // expected-error {{property access is using 'x' method which is unavailable}} \
168 // expected-warning {{property access is using 'setX:' method which is deprecated}}
169}