| 1 |
// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify -Wno-objc-root-class %s |
| 2 |
// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s |
| 3 |
|
| 4 |
#if __has_attribute(objc_requires_property_definitions) |
| 5 |
__attribute ((objc_requires_property_definitions)) |
| 6 |
#endif |
| 7 |
@interface NoAuto // expected-note 2 {{class with specified objc_requires_property_definitions attribute is declared here}} |
| 8 |
@property int NoAutoProp; // expected-note 2 {{property declared here}} |
| 9 |
@end |
| 10 |
|
| 11 |
@implementation NoAuto // expected-warning {{property 'NoAutoProp' requires method 'NoAutoProp' to be defined}} \ |
| 12 |
// expected-warning {{property 'NoAutoProp' requires method 'setNoAutoProp:'}} |
| 13 |
@end |
| 14 |
|
| 15 |
__attribute ((objc_requires_property_definitions)) // redundant, just for testing |
| 16 |
@interface Sub : NoAuto // expected-note 3 {{class with specified objc_requires_property_definitions attribute is declared here}} |
| 17 |
@property (copy) id SubProperty; // expected-note 2 {{property declared here}} |
| 18 |
@end |
| 19 |
|
| 20 |
@implementation Sub // expected-warning {{property 'SubProperty' requires method 'SubProperty' to be defined}} \ |
| 21 |
// expected-warning {{property 'SubProperty' requires method 'setSubProperty:' to be defined}} |
| 22 |
@end |
| 23 |
|
| 24 |
@interface Deep : Sub |
| 25 |
@property (copy) id DeepProperty; |
| 26 |
@property (copy) id DeepSynthProperty; |
| 27 |
@property (copy) id DeepMustSynthProperty; // expected-note {{property declared here}} |
| 28 |
@end |
| 29 |
|
| 30 |
@implementation Deep // expected-warning {{property 'DeepMustSynthProperty' requires method 'setDeepMustSynthProperty:' to be defined}} |
| 31 |
@dynamic DeepProperty; |
| 32 |
@synthesize DeepSynthProperty; |
| 33 |
- (id) DeepMustSynthProperty { return 0; } |
| 34 |
@end |
| 35 |
|
| 36 |
__attribute ((objc_requires_property_definitions)) // expected-error {{'objc_requires_property_definitions' attribute only applies to Objective-C interfaces}} |
| 37 |
@interface Deep(CAT) |
| 38 |
@end |
| 39 |
|
| 40 |
__attribute ((objc_requires_property_definitions)) // expected-error {{'objc_requires_property_definitions' attribute only applies to Objective-C interfaces}} |
| 41 |
@protocol P @end |
| 42 |
|
| 43 |
@interface NSObject @end |
| 44 |
@protocol Foo |
| 45 |
@property (readonly) char isFoo; // expected-note {{property declared here}} |
| 46 |
@property (readonly) char isNotFree; // expected-note {{property declared here}} |
| 47 |
@end |
| 48 |
|
| 49 |
@interface Bar : NSObject <Foo> |
| 50 |
@end |
| 51 |
|
| 52 |
@implementation Bar |
| 53 |
- (char)isFoo { |
| 54 |
return 0; |
| 55 |
} |
| 56 |
- (char)isNotFree { |
| 57 |
return 0; |
| 58 |
} |
| 59 |
@end |
| 60 |
|
| 61 |
@interface Baz : Bar |
| 62 |
@end |
| 63 |
|
| 64 |
@interface Baz () |
| 65 |
@property (readwrite) char isFoo; // expected-warning {{auto property synthesis will not synthesize property 'isFoo' because it is 'readwrite' but it will be synthesized 'readonly' via another property}} |
| 66 |
@property char Property1; // expected-warning {{auto property synthesis will not synthesize property 'Property1' because it cannot share an ivar with another synthesized property}} |
| 67 |
@property char Property2; |
| 68 |
@property (readwrite) char isNotFree; // expected-warning {{auto property synthesis will not synthesize property 'isNotFree'}} |
| 69 |
@end |
| 70 |
|
| 71 |
@implementation Baz { // expected-note {{detected while default synthesizing properties in class implementation}} |
| 72 |
char _isFoo; |
| 73 |
char _isNotFree; |
| 74 |
} |
| 75 |
@synthesize Property2 = Property1; // expected-note {{property synthesized here}} |
| 76 |
|
| 77 |
- (void) setIsNotFree : (char)Arg { |
| 78 |
_isNotFree = Arg; |
| 79 |
} |
| 80 |
|
| 81 |
@end |
| 82 |
|
| 83 |
// More test where such warnings should not be issued. |
| 84 |
@protocol MyProtocol |
| 85 |
-(void)setProp1:(id)x; |
| 86 |
@end |
| 87 |
|
| 88 |
@protocol P1 <MyProtocol> |
| 89 |
@end |
| 90 |
|
| 91 |
@interface B |
| 92 |
@property (readonly) id prop; // expected-note {{property declared here}} |
| 93 |
@property (readonly) id prop1; // expected-note {{property declared here}} |
| 94 |
@property (readonly) id prop2; // expected-note {{property declared here}} |
| 95 |
@end |
| 96 |
|
| 97 |
@interface B() |
| 98 |
-(void)setProp:(id)x; |
| 99 |
@end |
| 100 |
|
| 101 |
@interface B(cat) |
| 102 |
@property (readwrite) id prop2; |
| 103 |
@end |
| 104 |
|
| 105 |
@interface S : B<P1> |
| 106 |
@property (assign,readwrite) id prop; // expected-warning {{auto property synthesis will not synthesize property 'prop'}} |
| 107 |
@property (assign,readwrite) id prop1; // expected-warning {{auto property synthesis will not synthesize property 'prop1'}} |
| 108 |
@property (assign,readwrite) id prop2; // expected-warning {{auto property synthesis will not synthesize property 'prop2'}} |
| 109 |
@end |
| 110 |
|
| 111 |
@implementation S // expected-note 3 {{detected while default synthesizing properties in class implementation}} |
| 112 |
@end |
| 113 |
|
| 114 |
// No warning must be issued in this test. |
| 115 |
@interface ParentObject |
| 116 |
@end |
| 117 |
|
| 118 |
@protocol TestObject |
| 119 |
@property (readonly) int six; |
| 120 |
@end |
| 121 |
|
| 122 |
@interface TestObject : ParentObject <TestObject> |
| 123 |
@property int six; |
| 124 |
@end |
| 125 |
|
| 126 |
@implementation TestObject |
| 127 |
@synthesize six; |
| 128 |
@end |
| 129 |
|
| 130 |
// no warning in this test |
| 131 |
@interface ISAChallenge : NSObject { |
| 132 |
} |
| 133 |
|
| 134 |
@property (assign, readonly) int failureCount; |
| 135 |
@end |
| 136 |
|
| 137 |
@interface ISSAChallenge : ISAChallenge { |
| 138 |
int _failureCount; |
| 139 |
} |
| 140 |
@property (assign, readwrite) int failureCount; |
| 141 |
@end |
| 142 |
|
| 143 |
@implementation ISAChallenge |
| 144 |
- (int)failureCount { |
| 145 |
return 0; |
| 146 |
} |
| 147 |
@end |
| 148 |
|
| 149 |
@implementation ISSAChallenge |
| 150 |
|
| 151 |
@synthesize failureCount = _failureCount; |
| 152 |
@end |
| 153 |
|
| 154 |
__attribute ((objc_requires_property_definitions(1))) // expected-error {{'objc_requires_property_definitions' attribute takes no arguments}} |
| 155 |
@interface I1 |
| 156 |
@end |
| 157 |
|
| 158 |
@protocol SubFooling |
| 159 |
@property(nonatomic, readonly) id hoho; // expected-note 2 {{property declared here}} |
| 160 |
@end |
| 161 |
|
| 162 |
@protocol Fooing<SubFooling> |
| 163 |
@property(nonatomic, readonly) id muahahaha; // expected-note 2 {{property declared here}} |
| 164 |
@end |
| 165 |
|
| 166 |
typedef NSObject<Fooing> FooObject; |
| 167 |
|
| 168 |
@interface Okay : NSObject<Fooing> |
| 169 |
@end |
| 170 |
|
| 171 |
@implementation Okay // expected-warning {{auto property synthesis will not synthesize property 'muahahaha' declared in protocol 'Fooing'}} expected-warning {{auto property synthesis will not synthesize property 'hoho' declared in protocol 'SubFooling'}} |
| 172 |
@end // expected-note 2 {{add a '@synthesize' directive}} |
| 173 |
|
| 174 |
@interface Fail : FooObject |
| 175 |
@end |
| 176 |
|
| 177 |
@implementation Fail // expected-warning {{auto property synthesis will not synthesize property 'muahahaha' declared in protocol 'Fooing'}} expected-warning {{auto property synthesis will not synthesize property 'hoho' declared in protocol 'SubFooling'}} |
| 178 |
@end // expected-note 2 {{add a '@synthesize' directive}} |
| 179 |
|
| 180 |
@class NSURL; |
| 181 |
|
| 182 |
@interface Root |
| 183 |
- (void)setFileURL : (NSURL *) arg; |
| 184 |
- (void)setFile : (NSURL *) arg; |
| 185 |
- (NSURL *)fileSys; |
| 186 |
- (void)setFileSys : (NSURL *) arg; |
| 187 |
- (NSURL *)fileKerl; |
| 188 |
@end |
| 189 |
|
| 190 |
@interface SuperClass : Root |
| 191 |
- (NSURL *)fileURL; |
| 192 |
- (NSURL *)file; |
| 193 |
- (NSURL *)fileLog; |
| 194 |
- (void)setFileLog : (NSURL *) arg; |
| 195 |
- (void)setFileKerl : (NSURL *) arg; |
| 196 |
@end |
| 197 |
|
| 198 |
@protocol r16089191Protocol |
| 199 |
@property (readonly) NSURL *fileURL; |
| 200 |
@property (copy) NSURL *file; |
| 201 |
@property (copy) NSURL *fileSys; |
| 202 |
@property (copy) NSURL *fileLog; |
| 203 |
@property (copy) NSURL *fileKerl; |
| 204 |
@end |
| 205 |
|
| 206 |
@interface SubClass : SuperClass <r16089191Protocol> |
| 207 |
@end |
| 208 |
|
| 209 |
@implementation SubClass |
| 210 |
@end |