]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaObjC/property-deprecated-warning.m
Vendor import of clang trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / test / SemaObjC / property-deprecated-warning.m
1 // RUN: %clang_cc1  -fsyntax-only -triple thumbv6-apple-ios3.0 -verify -Wno-objc-root-class %s
2 // RUN: %clang_cc1 -D WARN_PARTIAL -Wpartial-availability -fsyntax-only -triple thumbv6-apple-ios3.0 -verify -Wno-objc-root-class %s
3 // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -triple thumbv6-apple-ios3.0 -verify -Wno-objc-root-class %s
4 // rdar://12324295
5
6 typedef signed char BOOL;
7
8 @protocol P
9 @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}}
10
11 #if defined(WARN_PARTIAL)
12 // expected-note@+2 {{'partialPtarget' has been marked as being introduced in iOS 5.0 here, but the deployment target is iOS 3.0.0}}
13 #endif
14 @property(nonatomic,assign) id partialPtarget __attribute__((availability(ios,introduced=5.0)));
15 @end
16
17 @protocol P1<P>
18 - (void)setPtarget:(id)arg;
19 - (void)setPartialPtarget:(id)arg;
20 @end
21
22
23 @interface UITableViewCell<P1>
24 @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}}
25
26 #if defined(WARN_PARTIAL)
27 // expected-note@+2 {{'setPartialTarget:' has been marked as being introduced in iOS 5.0 here, but the deployment target is iOS 3.0.0}}
28 #endif
29 @property(nonatomic,assign) id partialTarget __attribute__((availability(ios,introduced=5.0)));
30 @end
31
32 @interface PSTableCell : UITableViewCell
33  - (void)setTarget:(id)target;
34  - (void)setPartialTarget:(id)target;
35 @end
36
37 @interface UITableViewCell(UIDeprecated)
38 @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}} \
39                                                                                     // expected-note 4 {{property 'dep_target' is declared deprecated here}} \
40                                                                                     // expected-note 2 {{'setDep_target:' has been explicitly marked deprecated here}}
41
42 #if defined(WARN_PARTIAL)
43 // expected-note@+3 2 {{'partial_dep_target' has been marked as being introduced in iOS 5.0 here, but the deployment target is iOS 3.0.0}}
44 // expected-note@+2 2 {{'setPartial_dep_target:' has been marked as being introduced in iOS 5.0 here, but the deployment target is iOS 3.0.0}}
45 #endif
46 @property(nonatomic,assign) id partial_dep_target  __attribute__((availability(ios,introduced=5.0)));
47 @end
48
49 @implementation PSTableCell
50 - (void)setTarget:(id)target {};
51 - (void)setPartialTarget:(id)target {};
52 - (void)setPtarget:(id)val {};
53 - (void) Meth {
54   [self setTarget: (id)0]; // no-warning
55   [self setDep_target: [self dep_target]]; // expected-warning {{'dep_target' is deprecated: first deprecated in iOS 3.0}} \
56                                            // expected-warning {{'setDep_target:' is deprecated: first deprecated in iOS 3.0}}
57                                            
58   [self setPtarget: (id)0]; // no-warning
59   [self setPartialTarget: (id)0]; // no-warning
60 #if defined(WARN_PARTIAL)
61   // 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}}
62 #endif
63   [self setPartial_dep_target: [self partial_dep_target]];
64
65   [self setPartialPtarget: (id)0]; // no-warning
66 }
67 @end
68
69 @implementation UITableViewCell
70 @synthesize target;
71 @synthesize partialTarget;
72 @synthesize ptarget;
73 @synthesize partialPtarget;
74 - (void)setPtarget:(id)val {};
75 - (void)setPartialPtarget:(id)val {};
76 - (void)setTarget:(id)target {};
77 - (void)setPartialTarget:(id)target {};
78 - (void) Meth {
79   [self setTarget: (id)0]; // expected-warning {{'setTarget:' is deprecated: first deprecated in iOS 3.0}}
80   [self setDep_target: [self dep_target]]; // expected-warning {{'dep_target' is deprecated: first deprecated in iOS 3.0}} \
81                                            // expected-warning {{'setDep_target:' is deprecated: first deprecated in iOS 3.0}}
82
83   [self setPtarget: (id)0]; // no-warning
84
85 #if defined(WARN_PARTIAL)
86   // 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}}
87 #endif
88   [self setPartialTarget: (id)0];
89 #if defined(WARN_PARTIAL)
90   // 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}}
91 #endif
92   [self setPartial_dep_target: [self partial_dep_target]];
93   [self setPartialPtarget: (id)0]; // no-warning
94 }
95 @end
96
97
98 @interface CustomAccessorNames
99 @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}}
100
101 @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}}
102
103 #if defined(WARN_PARTIAL)
104 // expected-note@+2 {{'partialIsEnabled' has been marked as being introduced in iOS 5.0 here, but the deployment target is iOS 3.0.0}}
105 #endif
106 @property(getter=partialIsEnabled,assign) BOOL partialEnabled __attribute__((availability(ios,introduced=5.0)));
107
108 #if defined(WARN_PARTIAL)
109 // expected-note@+2 {{'partialSetNewDelegate:' has been marked as being introduced in iOS 5.0 here, but the deployment target is iOS 3.0.0}}
110 #endif
111 @property(setter=partialSetNewDelegate:,assign) id partialDelegate __attribute__((availability(ios,introduced=5.0)));
112 @end
113
114 void testCustomAccessorNames(CustomAccessorNames *obj) {
115   if ([obj isEnabled]) // expected-warning {{'isEnabled' is deprecated: first deprecated in iOS 3.0}}
116     [obj setNewDelegate:0]; // expected-warning {{'setNewDelegate:' is deprecated: first deprecated in iOS 3.0}}
117
118 #if defined(WARN_PARTIAL)
119   // 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}}
120 #endif
121   if ([obj partialIsEnabled])
122     [obj partialSetNewDelegate:0];
123 }
124
125
126 @interface ProtocolInCategory
127 @end
128
129 @interface ProtocolInCategory (TheCategory) <P1>
130 - (id)ptarget;
131 - (id)partialPtarget;
132 @end
133
134 id useDeprecatedProperty(ProtocolInCategory *obj, id<P> obj2, int flag) {
135   if (flag)
136     return [obj ptarget];  // no-warning
137   return [obj2 ptarget];   // expected-warning {{'ptarget' is deprecated: first deprecated in iOS 3.0}}
138
139   if (flag)
140     return [obj partialPtarget];  // no-warning
141 #if defined(WARN_PARTIAL)
142 // 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}}
143 #endif
144   return [obj2 partialPtarget];
145 }
146
147 // rdar://15951801
148 @interface Foo
149 {
150   int _x;
151 }
152 @property(nonatomic,readonly) int x;
153 - (void)setX:(int)x __attribute__ ((deprecated)); // expected-note 2 {{'setX:' has been explicitly marked deprecated here}}
154 - (int)x __attribute__ ((unavailable)); // expected-note {{'x' has been explicitly marked unavailable here}}
155 @end
156
157 @implementation Foo
158 - (void)setX:(int)x {
159         _x = x;
160 }
161 - (int)x {
162   return _x;
163 }
164 @end
165
166 void testUserAccessorAttributes(Foo *foo) {
167         [foo setX:5678]; // expected-warning {{'setX:' is deprecated}}
168         foo.x = foo.x; // expected-error {{property access is using 'x' method which is unavailable}} \
169                        // expected-warning {{property access is using 'setX:' method which is deprecated}}
170 }
171
172 // test implicit property does not emit duplicated warning.
173 @protocol Foo
174 - (int)size __attribute__((availability(ios,deprecated=3.0))); // expected-note {{'size' has been explicitly marked deprecated here}}
175 - (void)setSize: (int)x __attribute__((availability(ios,deprecated=2.0))); // expected-note {{'setSize:' has been explicitly marked deprecated here}}
176 @end
177
178 void testImplicitProperty(id<Foo> object) {
179   object.size = object.size; // expected-warning {{'size' is deprecated: first deprecated in iOS 3.0}} \
180                              // expected-warning {{'setSize:' is deprecated: first deprecated in iOS 2.0}}
181 }