Home | History | Annotate | Download | only in SemaObjC
      1 // RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s
      2 
      3 @interface NSString @end
      4 
      5 @interface NSObject @end
      6 
      7 @interface SynthItAll
      8 @property int howMany;
      9 @property (retain) NSString* what;
     10 @end
     11 
     12 @implementation SynthItAll
     13 #if !__has_feature(objc_default_synthesize_properties)
     14 @synthesize howMany, what;
     15 #endif
     16 @end
     17 
     18 
     19 @interface SynthSetter : NSObject
     20 @property (nonatomic) int howMany;  // REM: nonatomic to avoid warnings about only implementing one of the pair
     21 @property (nonatomic, retain) NSString* what;
     22 @end
     23 
     24 @implementation SynthSetter
     25 #if !__has_feature(objc_default_synthesize_properties)
     26 @synthesize howMany, what;
     27 #endif
     28 
     29 - (int) howMany {
     30     return self.howMany;
     31 }
     32 // - (void) setHowMany: (int) value
     33 
     34 - (NSString*) what {
     35     return self.what;
     36 }
     37 // - (void) setWhat: (NSString*) value    
     38 @end
     39 
     40 
     41 @interface SynthGetter : NSObject
     42 @property (nonatomic) int howMany;  // REM: nonatomic to avoid warnings about only implementing one of the pair
     43 @property (nonatomic, retain) NSString* what;
     44 @end
     45 
     46 @implementation SynthGetter
     47 #if !__has_feature(objc_default_synthesize_properties)
     48 @synthesize howMany, what;
     49 #endif
     50 
     51 // - (int) howMany
     52 - (void) setHowMany: (int) value {
     53     self.howMany = value;
     54 }
     55 
     56 // - (NSString*) what
     57 - (void) setWhat: (NSString*) value {
     58     if (self.what != value) {
     59     }
     60 }
     61 @end
     62 
     63 
     64 @interface SynthNone : NSObject
     65 @property int howMany;
     66 @property (retain) NSString* what;
     67 @end
     68 
     69 @implementation SynthNone
     70 #if !__has_feature(objc_default_synthesize_properties)
     71 @synthesize howMany, what;  // REM: Redundant anyway
     72 #endif
     73 
     74 - (int) howMany {
     75     return self.howMany;
     76 }
     77 - (void) setHowMany: (int) value {
     78     self.howMany = value;
     79 }
     80 
     81 - (NSString*) what {
     82     return self.what;
     83 }
     84 - (void) setWhat: (NSString*) value {
     85     if (self.what != value) {
     86     }
     87 }
     88 @end
     89 
     90 @protocol TopProtocol
     91   @property (readonly) id myString;
     92 @end
     93 
     94 @interface TopClass <TopProtocol> 
     95 {
     96   id myString; 
     97 }
     98 @end
     99 
    100 @interface SubClass : TopClass <TopProtocol> 
    101 @end
    102 
    103 @implementation SubClass @end 
    104 
    105 // rdar://7920807
    106 @interface C @end
    107 @interface C (Category)
    108 @property int p; // expected-note 2 {{property declared here}}
    109 @end
    110 @implementation C (Category) // expected-warning {{property 'p' requires method 'p' to be defined}} \
    111                              // expected-warning {{property 'p' requires method 'setP:' to be defined}}
    112 @end
    113 
    114 // Don't complain if a property is already @synthesized by usr.
    115 @interface D
    116 {
    117 }
    118 @property int PROP;
    119 @end
    120 
    121 @implementation D
    122 - (int) Meth { return self.PROP; }
    123 #if __has_feature(objc_default_synthesize_properties)
    124 @synthesize PROP=IVAR;
    125 #endif
    126 @end
    127 
    128 // rdar://10567333
    129 @protocol MyProtocol 
    130 @property (nonatomic, strong) NSString *requiredString; // expected-note {{property declared here}}
    131 
    132 @optional
    133 @property (nonatomic, strong) NSString *optionalString;
    134 @end
    135  
    136 @interface MyClass <MyProtocol> 
    137 @end
    138  
    139 @implementation MyClass // expected-warning {{auto property synthesis will not synthesize property declared in a protocol}}
    140 @end
    141