1 // RUN: %clang_cc1 -triple x86_64-apple-darwin9.0.0 -fsyntax-only -verify %s 2 // RUN: %clang_cc1 -D WARN_PARTIAL -Wpartial-availability -triple x86_64-apple-darwin9.0.0 -fsyntax-only -verify %s 3 4 @protocol P 5 - (void)proto_method __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note 2 {{'proto_method' has been explicitly marked deprecated here}} 6 7 #if defined(WARN_PARTIAL) 8 // expected-note@+2 2 {{'partial_proto_method' has been explicitly marked partial here}} 9 #endif 10 - (void)partial_proto_method __attribute__((availability(macosx,introduced=10.8))); 11 @end 12 13 @interface A <P> 14 - (void)method __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note {{'method' has been explicitly marked deprecated here}} 15 #if defined(WARN_PARTIAL) 16 // expected-note@+2 {{'partialMethod' has been explicitly marked partial here}} 17 #endif 18 - (void)partialMethod __attribute__((availability(macosx,introduced=10.8))); 19 20 - (void)overridden __attribute__((availability(macosx,introduced=10.3))); // expected-note{{overridden method is here}} 21 - (void)overridden2 __attribute__((availability(macosx,introduced=10.3))); 22 - (void)overridden3 __attribute__((availability(macosx,deprecated=10.3))); 23 - (void)overridden4 __attribute__((availability(macosx,deprecated=10.3))); // expected-note{{overridden method is here}} 24 - (void)overridden5 __attribute__((availability(macosx,unavailable))); 25 - (void)overridden6 __attribute__((availability(macosx,introduced=10.3))); // expected-note{{overridden method is here}} 26 - (void)unavailableMethod __attribute__((unavailable)); 27 @end 28 29 // rdar://11475360 30 @interface B : A 31 - (void)method; // NOTE: we expect 'method' to *not* inherit availability. 32 - (void)partialMethod; // Likewise. 33 - (void)overridden __attribute__((availability(macosx,introduced=10.4))); // expected-warning{{overriding method introduced after overridden method on macOS (10.4 vs. 10.3)}} 34 - (void)overridden2 __attribute__((availability(macosx,introduced=10.2))); 35 - (void)overridden3 __attribute__((availability(macosx,deprecated=10.4))); 36 - (void)overridden4 __attribute__((availability(macosx,deprecated=10.2))); // expected-warning{{overriding method deprecated before overridden method on macOS (10.3 vs. 10.2)}} 37 - (void)overridden5 __attribute__((availability(macosx,introduced=10.3))); 38 - (void)overridden6 __attribute__((availability(macosx,unavailable))); // expected-warning{{overriding method cannot be unavailable on macOS when its overridden method is available}} 39 - (void)unavailableMethod; // does *not* inherit unavailability 40 @end 41 42 void f(A *a, B *b) { 43 [a method]; // expected-warning{{'method' is deprecated: first deprecated in macOS 10.2}} 44 [b method]; // no-warning 45 [a proto_method]; // expected-warning{{'proto_method' is deprecated: first deprecated in macOS 10.2}} 46 [b proto_method]; // expected-warning{{'proto_method' is deprecated: first deprecated in macOS 10.2}} 47 48 #if defined(WARN_PARTIAL) 49 // expected-warning@+2 {{'partialMethod' is partial: introduced in macOS 10.8}} expected-note@+2 {{explicitly redeclare 'partialMethod' to silence this warning}} 50 #endif 51 [a partialMethod]; 52 [b partialMethod]; // no warning 53 #if defined(WARN_PARTIAL) 54 // expected-warning@+2 {{'partial_proto_method' is partial: introduced in macOS 10.8}} expected-note@+2 {{explicitly redeclare 'partial_proto_method' to silence this warning}} 55 #endif 56 [a partial_proto_method]; 57 #if defined(WARN_PARTIAL) 58 // expected-warning@+2 {{'partial_proto_method' is partial: introduced in macOS 10.8}} expected-note@+2 {{explicitly redeclare 'partial_proto_method' to silence this warning}} 59 #endif 60 [b partial_proto_method]; 61 } 62 63 @interface A (NewAPI) 64 - (void)partialMethod; 65 - (void)partial_proto_method; 66 @end 67 68 void f_after_redecl(A *a, B *b) { 69 [a partialMethod]; // no warning 70 [b partialMethod]; // no warning 71 [a partial_proto_method]; // no warning 72 [b partial_proto_method]; // no warning 73 } 74 75 // Test case for <rdar://problem/11627873>. Warn about 76 // using a deprecated method when that method is re-implemented in a 77 // subclass where the redeclared method is not deprecated. 78 @interface C 79 - (void) method __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note {{'method' has been explicitly marked deprecated here}} 80 @end 81 82 @interface D : C 83 - (void) method; 84 @end 85 86 @interface E : D 87 - (void) method; 88 @end 89 90 @implementation D 91 - (void) method { 92 [super method]; // expected-warning {{'method' is deprecated: first deprecated in macOS 10.2}} 93 } 94 @end 95 96 @implementation E 97 - (void) method { 98 [super method]; // no-warning 99 } 100 @end 101 102 // rdar://18059669 103 @class NSMutableArray; 104 105 @interface NSDictionary 106 + (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ... __attribute__((sentinel(0,1))); 107 @end 108 109 @class NSString; 110 111 extern NSString *NSNibTopLevelObjects __attribute__((availability(macosx,introduced=10.0 ,deprecated=10.8,message="" ))); 112 id NSNibOwner, topNibObjects; 113 114 @interface AppDelegate (SIEImport) // expected-error {{cannot find interface declaration for 'AppDelegate'}} 115 116 -(void)__attribute__((ibaction))importFromSIE:(id)sender; 117 118 @end 119 120 @implementation AppDelegate (SIEImport) // expected-error {{cannot find interface declaration for 'AppDelegate'}} 121 122 -(void)__attribute__((ibaction))importFromSIE:(id)sender { 123 124 NSMutableArray *topNibObjects; 125 NSDictionary *nibLoadDict = [NSDictionary dictionaryWithObjectsAndKeys:self, NSNibOwner, topNibObjects, NSNibTopLevelObjects, ((void *)0)]; 126 } 127 128 @end 129 130 @protocol PartialProt 131 - (void)ppartialMethod __attribute__((availability(macosx,introduced=10.8))); 132 + (void)ppartialMethod __attribute__((availability(macosx,introduced=10.8))); 133 @end 134 135 @interface PartialI <PartialProt> 136 - (void)partialMethod __attribute__((availability(macosx,introduced=10.8))); 137 + (void)partialMethod __attribute__((availability(macosx,introduced=10.8))); 138 @end 139 140 @interface PartialI () 141 - (void)ipartialMethod1 __attribute__((availability(macosx,introduced=10.8))); 142 #if defined(WARN_PARTIAL) 143 // expected-note@+2 {{'ipartialMethod2' has been explicitly marked partial here}} 144 #endif 145 - (void)ipartialMethod2 __attribute__((availability(macosx,introduced=10.8))); 146 + (void)ipartialMethod1 __attribute__((availability(macosx,introduced=10.8))); 147 #if defined(WARN_PARTIAL) 148 // expected-note@+2 {{'ipartialMethod2' has been explicitly marked partial here}} 149 #endif 150 + (void)ipartialMethod2 __attribute__((availability(macosx,introduced=10.8))); 151 @end 152 153 @interface PartialI (Redecls) 154 - (void)partialMethod; 155 - (void)ipartialMethod1; 156 - (void)ppartialMethod; 157 + (void)partialMethod; 158 + (void)ipartialMethod1; 159 + (void)ppartialMethod; 160 @end 161 162 void partialfun(PartialI* a) { 163 [a partialMethod]; // no warning 164 [a ipartialMethod1]; // no warning 165 #if defined(WARN_PARTIAL) 166 // expected-warning@+2 {{'ipartialMethod2' is partial: introduced in macOS 10.8}} expected-note@+2 {{explicitly redeclare 'ipartialMethod2' to silence this warning}} 167 #endif 168 [a ipartialMethod2]; 169 [a ppartialMethod]; // no warning 170 [PartialI partialMethod]; // no warning 171 [PartialI ipartialMethod1]; // no warning 172 #if defined(WARN_PARTIAL) 173 // expected-warning@+2 {{'ipartialMethod2' is partial: introduced in macOS 10.8}} expected-note@+2 {{explicitly redeclare 'ipartialMethod2' to silence this warning}} 174 #endif 175 [PartialI ipartialMethod2]; 176 [PartialI ppartialMethod]; // no warning 177 } 178 179 #if defined(WARN_PARTIAL) 180 // expected-note@+2 {{'PartialI2' has been explicitly marked partial here}} 181 #endif 182 __attribute__((availability(macosx, introduced = 10.8))) @interface PartialI2 183 @end 184 185 #if defined(WARN_PARTIAL) 186 // expected-warning@+2 {{'PartialI2' is partial: introduced in macOS 10.8}} expected-note@+2 {{explicitly redeclare 'PartialI2' to silence this warning}} 187 #endif 188 void partialinter1(PartialI2* p) { 189 } 190 191 @class PartialI2; 192 193 void partialinter2(PartialI2* p) { // no warning 194 } 195 196 197 // Test that both the use of the 'typedef' and the enum constant 198 // produces an error. rdar://problem/20903588 199 #define UNAVAILABLE __attribute__((unavailable("not available"))) 200 201 typedef enum MyEnum : int MyEnum; 202 enum MyEnum : int { // expected-note {{'MyEnum' has been explicitly marked unavailable here}} 203 MyEnum_Blah UNAVAILABLE, // expected-note {{'MyEnum_Blah' has been explicitly marked unavailable here}} 204 } UNAVAILABLE; 205 206 void use_myEnum() { 207 // expected-error@+2 {{'MyEnum' is unavailable: not available}} 208 // expected-error@+1 {{MyEnum_Blah' is unavailable: not available}} 209 MyEnum e = MyEnum_Blah; 210 } 211 212 // Test that the availability of (optional) protocol methods is not 213 // inherited be implementations of those protocol methods. 214 @protocol AvailabilityP2 215 @optional 216 -(void)methodA __attribute__((availability(macosx,introduced=10.1,deprecated=10.2))); // expected-note 4{{'methodA' has been explicitly marked deprecated here}} \ 217 // expected-note 2{{protocol method is here}} 218 -(void)methodB __attribute__((unavailable)); // expected-note 4{{'methodB' has been explicitly marked unavailable here}} 219 -(void)methodC; 220 @end 221 222 void testAvailabilityP2(id<AvailabilityP2> obj) { 223 [obj methodA]; // expected-warning{{'methodA' is deprecated: first deprecated in macOS 10.2}} 224 [obj methodB]; // expected-error{{'methodB' is unavailable}} 225 } 226 227 @interface ImplementsAvailabilityP2a <AvailabilityP2> 228 -(void)methodA; 229 -(void)methodB; 230 @end 231 232 void testImplementsAvailabilityP2a(ImplementsAvailabilityP2a *obj) { 233 [obj methodA]; // okay: availability not inherited 234 [obj methodB]; // okay: unavailability not inherited 235 } 236 237 __attribute__((objc_root_class)) 238 @interface ImplementsAvailabilityP2b <AvailabilityP2> 239 @end 240 241 @implementation ImplementsAvailabilityP2b 242 -(void)methodA { 243 // Make sure we're not inheriting availability. 244 id<AvailabilityP2> obj = self; 245 [obj methodA]; // expected-warning{{'methodA' is deprecated: first deprecated in macOS 10.2}} 246 [obj methodB]; // expected-error{{'methodB' is unavailable}} 247 } 248 -(void)methodB { 249 // Make sure we're not inheriting unavailability. 250 id<AvailabilityP2> obj = self; 251 [obj methodA]; // expected-warning{{'methodA' is deprecated: first deprecated in macOS 10.2}} 252 [obj methodB]; // expected-error{{'methodB' is unavailable}} 253 } 254 255 @end 256 257 void testImplementsAvailabilityP2b(ImplementsAvailabilityP2b *obj) { 258 // still get warnings/errors because we see the protocol version. 259 260 [obj methodA]; // expected-warning{{'methodA' is deprecated: first deprecated in macOS 10.2}} 261 [obj methodB]; // expected-error{{'methodB' is unavailable}} 262 } 263 264 __attribute__((objc_root_class)) 265 @interface ImplementsAvailabilityP2c <AvailabilityP2> 266 -(void)methodA __attribute__((availability(macosx,introduced=10.2))); // expected-warning{{method introduced after the protocol method it implements on macOS (10.2 vs. 10.1)}} 267 -(void)methodB __attribute__((unavailable)); 268 @end 269 270 __attribute__((objc_root_class)) 271 @interface ImplementsAvailabilityP2d <AvailabilityP2> 272 @end 273 274 @implementation ImplementsAvailabilityP2d 275 -(void)methodA __attribute__((availability(macosx,introduced=10.2))) // expected-warning{{method introduced after the protocol method it implements on macOS (10.2 vs. 10.1)}} 276 { 277 } 278 -(void)methodB __attribute__((unavailable)) { 279 } 280 @end 281 282 __attribute__((objc_root_class)) 283 @interface InheritUnavailableSuper 284 -(void)method __attribute__((unavailable)); // expected-note{{'method' has been explicitly marked unavailable here}} 285 @end 286 287 @interface InheritUnavailableSub : InheritUnavailableSuper 288 -(void)method; 289 @end 290 291 @implementation InheritUnavailableSub 292 -(void)method { 293 InheritUnavailableSuper *obj = self; 294 [obj method]; // expected-error{{'method' is unavailable}} 295 } 296 @end 297