| Rafael Espindola | ea1ba0a | 2013-09-27 20:21:48 +0000 | [diff] [blame] | 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 |
| Fariborz Jahanian | 3c9707b | 2012-01-03 19:46:00 +0000 | [diff] [blame] | 3 | |
| Ted Kremenek | 0c2c90b | 2012-01-05 22:47:47 +0000 | [diff] [blame] | 4 | #if __has_attribute(objc_requires_property_definitions) |
| 5 | __attribute ((objc_requires_property_definitions)) |
| Fariborz Jahanian | a28a78e | 2012-01-04 22:29:28 +0000 | [diff] [blame] | 6 | #endif |
| Ted Kremenek | 0c2c90b | 2012-01-05 22:47:47 +0000 | [diff] [blame] | 7 | @interface NoAuto // expected-note 2 {{class with specified objc_requires_property_definitions attribute is declared here}} |
| Fariborz Jahanian | 3c9707b | 2012-01-03 19:46:00 +0000 | [diff] [blame] | 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 | |
| Ted Kremenek | 0c2c90b | 2012-01-05 22:47:47 +0000 | [diff] [blame] | 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}} |
| Fariborz Jahanian | 3c9707b | 2012-01-03 19:46:00 +0000 | [diff] [blame] | 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 | |
| Alex Lorenz | f937139 | 2017-03-23 11:44:25 +0000 | [diff] [blame] | 36 | __attribute ((objc_requires_property_definitions)) // expected-error {{'objc_requires_property_definitions' attribute only applies to Objective-C interfaces}} |
| 37 | @interface Deep(CAT) |
| Fariborz Jahanian | 7249e36 | 2012-01-03 22:52:32 +0000 | [diff] [blame] | 38 | @end |
| 39 | |
| Aaron Ballman | f361453 | 2013-11-24 20:36:50 +0000 | [diff] [blame] | 40 | __attribute ((objc_requires_property_definitions)) // expected-error {{'objc_requires_property_definitions' attribute only applies to Objective-C interfaces}} |
| Fariborz Jahanian | 7249e36 | 2012-01-03 22:52:32 +0000 | [diff] [blame] | 41 | @protocol P @end |
| Fariborz Jahanian | 9d25a48 | 2013-03-12 19:46:17 +0000 | [diff] [blame] | 42 | |
| 43 | // rdar://13388503 |
| 44 | @interface NSObject @end |
| 45 | @protocol Foo |
| 46 | @property (readonly) char isFoo; // expected-note {{property declared here}} |
| Fariborz Jahanian | c985a7f | 2014-10-10 22:08:23 +0000 | [diff] [blame] | 47 | @property (readonly) char isNotFree; // expected-note {{property declared here}} |
| Fariborz Jahanian | 9d25a48 | 2013-03-12 19:46:17 +0000 | [diff] [blame] | 48 | @end |
| 49 | |
| 50 | @interface Bar : NSObject <Foo> |
| 51 | @end |
| 52 | |
| 53 | @implementation Bar |
| 54 | - (char)isFoo { |
| 55 | return 0; |
| 56 | } |
| Fariborz Jahanian | b0df66b | 2013-03-12 22:22:38 +0000 | [diff] [blame] | 57 | - (char)isNotFree { |
| 58 | return 0; |
| 59 | } |
| Fariborz Jahanian | 9d25a48 | 2013-03-12 19:46:17 +0000 | [diff] [blame] | 60 | @end |
| 61 | |
| 62 | @interface Baz : Bar |
| 63 | @end |
| 64 | |
| 65 | @interface Baz () |
| 66 | @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}} |
| 67 | @property char Property1; // expected-warning {{auto property synthesis will not synthesize property 'Property1' because it cannot share an ivar with another synthesized property}} |
| 68 | @property char Property2; |
| Fariborz Jahanian | 6c9ee7b | 2014-07-26 20:52:26 +0000 | [diff] [blame] | 69 | @property (readwrite) char isNotFree; // expected-warning {{auto property synthesis will not synthesize property 'isNotFree'}} |
| Fariborz Jahanian | 9d25a48 | 2013-03-12 19:46:17 +0000 | [diff] [blame] | 70 | @end |
| 71 | |
| Fariborz Jahanian | 6c9ee7b | 2014-07-26 20:52:26 +0000 | [diff] [blame] | 72 | @implementation Baz { // expected-note {{detected while default synthesizing properties in class implementation}} |
| Fariborz Jahanian | 9d25a48 | 2013-03-12 19:46:17 +0000 | [diff] [blame] | 73 | char _isFoo; |
| Fariborz Jahanian | b0df66b | 2013-03-12 22:22:38 +0000 | [diff] [blame] | 74 | char _isNotFree; |
| Fariborz Jahanian | 9d25a48 | 2013-03-12 19:46:17 +0000 | [diff] [blame] | 75 | } |
| 76 | @synthesize Property2 = Property1; // expected-note {{property synthesized here}} |
| Fariborz Jahanian | b0df66b | 2013-03-12 22:22:38 +0000 | [diff] [blame] | 77 | |
| 78 | - (void) setIsNotFree : (char)Arg { |
| 79 | _isNotFree = Arg; |
| 80 | } |
| 81 | |
| Fariborz Jahanian | 9d25a48 | 2013-03-12 19:46:17 +0000 | [diff] [blame] | 82 | @end |
| Fariborz Jahanian | 1446b34 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 83 | |
| 84 | // More test where such warnings should not be issued. |
| 85 | @protocol MyProtocol |
| 86 | -(void)setProp1:(id)x; |
| 87 | @end |
| 88 | |
| 89 | @protocol P1 <MyProtocol> |
| 90 | @end |
| 91 | |
| 92 | @interface B |
| Fariborz Jahanian | c985a7f | 2014-10-10 22:08:23 +0000 | [diff] [blame] | 93 | @property (readonly) id prop; // expected-note {{property declared here}} |
| 94 | @property (readonly) id prop1; // expected-note {{property declared here}} |
| 95 | @property (readonly) id prop2; // expected-note {{property declared here}} |
| Fariborz Jahanian | 1446b34 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 96 | @end |
| 97 | |
| 98 | @interface B() |
| 99 | -(void)setProp:(id)x; |
| 100 | @end |
| 101 | |
| 102 | @interface B(cat) |
| 103 | @property (readwrite) id prop2; |
| 104 | @end |
| 105 | |
| 106 | @interface S : B<P1> |
| Fariborz Jahanian | 6c9ee7b | 2014-07-26 20:52:26 +0000 | [diff] [blame] | 107 | @property (assign,readwrite) id prop; // expected-warning {{auto property synthesis will not synthesize property 'prop'}} |
| 108 | @property (assign,readwrite) id prop1; // expected-warning {{auto property synthesis will not synthesize property 'prop1'}} |
| 109 | @property (assign,readwrite) id prop2; // expected-warning {{auto property synthesis will not synthesize property 'prop2'}} |
| Fariborz Jahanian | 1446b34 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 110 | @end |
| 111 | |
| Fariborz Jahanian | 6c9ee7b | 2014-07-26 20:52:26 +0000 | [diff] [blame] | 112 | @implementation S // expected-note 3 {{detected while default synthesizing properties in class implementation}} |
| Fariborz Jahanian | 1446b34 | 2013-03-21 20:50:53 +0000 | [diff] [blame] | 113 | @end |
| Fariborz Jahanian | 4614524 | 2013-06-07 18:32:55 +0000 | [diff] [blame] | 114 | |
| 115 | // rdar://14085456 |
| 116 | // No warning must be issued in this test. |
| 117 | @interface ParentObject |
| 118 | @end |
| 119 | |
| 120 | @protocol TestObject |
| 121 | @property (readonly) int six; |
| 122 | @end |
| 123 | |
| 124 | @interface TestObject : ParentObject <TestObject> |
| 125 | @property int six; |
| 126 | @end |
| 127 | |
| 128 | @implementation TestObject |
| 129 | @synthesize six; |
| 130 | @end |
| 131 | |
| Fariborz Jahanian | bbc126e | 2013-06-07 20:26:51 +0000 | [diff] [blame] | 132 | // rdar://14094682 |
| 133 | // no warning in this test |
| 134 | @interface ISAChallenge : NSObject { |
| 135 | } |
| 136 | |
| 137 | @property (assign, readonly) int failureCount; |
| 138 | @end |
| 139 | |
| 140 | @interface ISSAChallenge : ISAChallenge { |
| 141 | int _failureCount; |
| 142 | } |
| 143 | @property (assign, readwrite) int failureCount; |
| 144 | @end |
| 145 | |
| 146 | @implementation ISAChallenge |
| 147 | - (int)failureCount { |
| 148 | return 0; |
| 149 | } |
| 150 | @end |
| 151 | |
| 152 | @implementation ISSAChallenge |
| 153 | |
| 154 | @synthesize failureCount = _failureCount; |
| 155 | @end |
| 156 | |
| Aaron Ballman | b724338 | 2013-07-23 19:30:11 +0000 | [diff] [blame] | 157 | __attribute ((objc_requires_property_definitions(1))) // expected-error {{'objc_requires_property_definitions' attribute takes no arguments}} |
| Aaron Ballman | 283ef42 | 2013-07-23 15:16:00 +0000 | [diff] [blame] | 158 | @interface I1 |
| 159 | @end |
| Fariborz Jahanian | b7c5f74 | 2013-09-25 19:36:32 +0000 | [diff] [blame] | 160 | |
| 161 | // rdar://15051465 |
| 162 | @protocol SubFooling |
| 163 | @property(nonatomic, readonly) id hoho; // expected-note 2 {{property declared here}} |
| 164 | @end |
| 165 | |
| 166 | @protocol Fooing<SubFooling> |
| 167 | @property(nonatomic, readonly) id muahahaha; // expected-note 2 {{property declared here}} |
| 168 | @end |
| 169 | |
| 170 | typedef NSObject<Fooing> FooObject; |
| 171 | |
| 172 | @interface Okay : NSObject<Fooing> |
| 173 | @end |
| 174 | |
| Ted Kremenek | 6d69ac8 | 2013-12-12 23:40:14 +0000 | [diff] [blame] | 175 | @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'}} |
| Alex Lorenz | 6c9af50 | 2017-07-03 10:12:24 +0000 | [diff] [blame] | 176 | @end // expected-note 2 {{add a '@synthesize' directive}} |
| Fariborz Jahanian | b7c5f74 | 2013-09-25 19:36:32 +0000 | [diff] [blame] | 177 | |
| 178 | @interface Fail : FooObject |
| 179 | @end |
| 180 | |
| Ted Kremenek | 6d69ac8 | 2013-12-12 23:40:14 +0000 | [diff] [blame] | 181 | @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'}} |
| Alex Lorenz | 6c9af50 | 2017-07-03 10:12:24 +0000 | [diff] [blame] | 182 | @end // expected-note 2 {{add a '@synthesize' directive}} |
| Fariborz Jahanian | b7c5f74 | 2013-09-25 19:36:32 +0000 | [diff] [blame] | 183 | |
| Fariborz Jahanian | 6766f8d | 2014-03-05 23:44:00 +0000 | [diff] [blame] | 184 | // rdar://16089191 |
| 185 | @class NSURL; |
| 186 | |
| 187 | @interface Root |
| 188 | - (void)setFileURL : (NSURL *) arg; |
| 189 | - (void)setFile : (NSURL *) arg; |
| 190 | - (NSURL *)fileSys; |
| 191 | - (void)setFileSys : (NSURL *) arg; |
| 192 | - (NSURL *)fileKerl; |
| 193 | @end |
| 194 | |
| 195 | @interface SuperClass : Root |
| 196 | - (NSURL *)fileURL; |
| 197 | - (NSURL *)file; |
| 198 | - (NSURL *)fileLog; |
| 199 | - (void)setFileLog : (NSURL *) arg; |
| 200 | - (void)setFileKerl : (NSURL *) arg; |
| 201 | @end |
| 202 | |
| 203 | @protocol r16089191Protocol |
| 204 | @property (readonly) NSURL *fileURL; |
| Bob Wilson | 3ca7904 | 2014-03-11 17:17:16 +0000 | [diff] [blame] | 205 | @property (copy) NSURL *file; |
| 206 | @property (copy) NSURL *fileSys; |
| 207 | @property (copy) NSURL *fileLog; |
| 208 | @property (copy) NSURL *fileKerl; |
| Fariborz Jahanian | 6766f8d | 2014-03-05 23:44:00 +0000 | [diff] [blame] | 209 | @end |
| 210 | |
| 211 | @interface SubClass : SuperClass <r16089191Protocol> |
| 212 | @end |
| 213 | |
| 214 | @implementation SubClass |
| 215 | @end |