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