Home | History | Annotate | Download | only in SemaObjC
      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 {{property 'partialPtarget' is declared partial here}} expected-note@+2 {{'partialPtarget' has been explicitly marked partial here}}
     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 {{property 'partialTarget' is declared partial here}} expected-note@+2 {{'setPartialTarget:' has been explicitly marked partial here}}
     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@+2 4 {{property 'partial_dep_target' is declared partial here}} 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}}
     44 #endif
     45 @property(nonatomic,assign) id partial_dep_target  __attribute__((availability(ios,introduced=5.0)));
     46 @end
     47 
     48 @implementation PSTableCell
     49 - (void)setTarget:(id)target {};
     50 - (void)setPartialTarget:(id)target {};
     51 - (void)setPtarget:(id)val {};
     52 - (void) Meth {
     53   [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
     58   [self setPartialTarget: (id)0]; // no-warning
     59 #if defined(WARN_PARTIAL)
     60   // expected-warning@+2 {{'partial_dep_target' is partial: introduced in iOS 5.0}} expected-warning@+2 {{'setPartial_dep_target:' is partial: introduced in iOS 5.0}} expected-note@+2 {{explicitly redeclare 'partial_dep_target' to silence this warning}} expected-note@+2 {{explicitly redeclare 'setPartial_dep_target:' to silence this warning}}
     61 #endif
     62   [self setPartial_dep_target: [self partial_dep_target]];
     63 
     64   [self setPartialPtarget: (id)0]; // no-warning
     65 }
     66 @end
     67 
     68 @implementation UITableViewCell
     69 @synthesize target;
     70 @synthesize partialTarget;
     71 @synthesize ptarget;
     72 @synthesize partialPtarget;
     73 - (void)setPtarget:(id)val {};
     74 - (void)setPartialPtarget:(id)val {};
     75 - (void)setTarget:(id)target {};
     76 - (void)setPartialTarget:(id)target {};
     77 - (void) Meth {
     78   [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}}
     81 
     82   [self setPtarget: (id)0]; // no-warning
     83 
     84 #if defined(WARN_PARTIAL)
     85   // expected-warning@+2 {{'setPartialTarget:' is partial: introduced in iOS 5.0}} expected-note@+2 {{explicitly redeclare 'setPartialTarget:' to silence this warning}}
     86 #endif
     87   [self setPartialTarget: (id)0];
     88 #if defined(WARN_PARTIAL)
     89   // expected-warning@+2 {{'partial_dep_target' is partial: introduced in iOS 5.0}} expected-warning@+2 {{'setPartial_dep_target:' is partial: introduced in iOS 5.0}} expected-note@+2 {{explicitly redeclare 'partial_dep_target' to silence this warning}} expected-note@+2 {{explicitly redeclare 'setPartial_dep_target:' to silence this warning}}
     90 #endif
     91   [self setPartial_dep_target: [self partial_dep_target]];
     92   [self setPartialPtarget: (id)0]; // no-warning
     93 }
     94 @end
     95 
     96 
     97 @interface CustomAccessorNames
     98 @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}}
     99 
    100 @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}}
    101 
    102 #if defined(WARN_PARTIAL)
    103 // expected-note@+2 {{property 'partialEnabled' is declared partial here}} expected-note@+2 {{'partialIsEnabled' has been explicitly marked partial here}}
    104 #endif
    105 @property(getter=partialIsEnabled,assign) BOOL partialEnabled __attribute__((availability(ios,introduced=5.0)));
    106 
    107 #if defined(WARN_PARTIAL)
    108 // expected-note@+2 {{property 'partialDelegate' is declared partial here}} expected-note@+2 {{'partialSetNewDelegate:' has been explicitly marked partial here}}
    109 #endif
    110 @property(setter=partialSetNewDelegate:,assign) id partialDelegate __attribute__((availability(ios,introduced=5.0)));
    111 @end
    112 
    113 void 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}}
    116 
    117 #if defined(WARN_PARTIAL)
    118 // expected-warning@+2 {{'partialIsEnabled' is partial: introduced in iOS 5.0}} expected-warning@+3 {{'partialSetNewDelegate:' is partial: introduced in iOS 5.0}} expected-note@+2 {{explicitly redeclare 'partialIsEnabled' to silence this warning}} expected-note@+3 {{explicitly redeclare 'partialSetNewDelegate:' to silence this warning}}
    119 #endif
    120   if ([obj partialIsEnabled])
    121     [obj partialSetNewDelegate:0];
    122 }
    123 
    124 
    125 @interface ProtocolInCategory
    126 @end
    127 
    128 @interface ProtocolInCategory (TheCategory) <P1>
    129 - (id)ptarget;
    130 - (id)partialPtarget;
    131 @end
    132 
    133 id 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}}
    137 
    138   if (flag)
    139     return [obj partialPtarget];  // no-warning
    140 #if defined(WARN_PARTIAL)
    141 // expected-warning@+2 {{'partialPtarget' is partial: introduced in iOS 5.0}} expected-note@+2 {{explicitly redeclare 'partialPtarget' to silence this warning}}
    142 #endif
    143   return [obj2 partialPtarget];
    144 }
    145 
    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 
    165 void 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 }
    170