Patrick Beard | b2f6820 | 2012-04-06 18:12:22 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -x objective-c -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s |
| 2 | // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -fobjc-default-synthesize-properties -verify -Wno-objc-root-class %s |
Fariborz Jahanian | eb4f2c5 | 2012-01-03 19:46:00 +0000 | [diff] [blame] | 3 | |
Ted Kremenek | 71207fc | 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 | fe40bf8 | 2012-01-04 22:29:28 +0000 | [diff] [blame] | 6 | #endif |
Ted Kremenek | 71207fc | 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 | eb4f2c5 | 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 | 71207fc | 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 | eb4f2c5 | 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 | |
Ted Kremenek | 71207fc | 2012-01-05 22:47:47 +0000 | [diff] [blame] | 36 | __attribute ((objc_requires_property_definitions)) |
Fariborz Jahanian | 341b8be | 2012-01-03 22:52:32 +0000 | [diff] [blame] | 37 | @interface Deep(CAT) // expected-error {{attributes may not be specified on a category}} |
| 38 | @end |
| 39 | |
Ted Kremenek | 71207fc | 2012-01-05 22:47:47 +0000 | [diff] [blame] | 40 | __attribute ((objc_requires_property_definitions)) // expected-error {{objc_requires_property_definitions attribute may only be specified on a class}} |
Fariborz Jahanian | 341b8be | 2012-01-03 22:52:32 +0000 | [diff] [blame] | 41 | @protocol P @end |
Fariborz Jahanian | 6114a3c | 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 | 1d0d2fe | 2013-03-12 22:22:38 +0000 | [diff] [blame] | 47 | @property (readonly) char isNotFree; |
Fariborz Jahanian | 6114a3c | 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 | 1d0d2fe | 2013-03-12 22:22:38 +0000 | [diff] [blame] | 57 | - (char)isNotFree { |
| 58 | return 0; |
| 59 | } |
Fariborz Jahanian | 6114a3c | 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 | 1d0d2fe | 2013-03-12 22:22:38 +0000 | [diff] [blame] | 69 | @property (readwrite) char isNotFree; |
Fariborz Jahanian | 6114a3c | 2013-03-12 19:46:17 +0000 | [diff] [blame] | 70 | @end |
| 71 | |
| 72 | @implementation Baz { |
| 73 | char _isFoo; |
Fariborz Jahanian | 1d0d2fe | 2013-03-12 22:22:38 +0000 | [diff] [blame] | 74 | char _isNotFree; |
Fariborz Jahanian | 6114a3c | 2013-03-12 19:46:17 +0000 | [diff] [blame] | 75 | } |
| 76 | @synthesize Property2 = Property1; // expected-note {{property synthesized here}} |
Fariborz Jahanian | 1d0d2fe | 2013-03-12 22:22:38 +0000 | [diff] [blame] | 77 | |
| 78 | - (void) setIsNotFree : (char)Arg { |
| 79 | _isNotFree = Arg; |
| 80 | } |
| 81 | |
Fariborz Jahanian | 6114a3c | 2013-03-12 19:46:17 +0000 | [diff] [blame] | 82 | @end |
Fariborz Jahanian | 5bdaef5 | 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 |
| 93 | @property (readonly) id prop; |
| 94 | @property (readonly) id prop1; |
| 95 | @property (readonly) id prop2; |
| 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> |
| 107 | @property (assign,readwrite) id prop; |
| 108 | @property (assign,readwrite) id prop1; |
| 109 | @property (assign,readwrite) id prop2; |
| 110 | @end |
| 111 | |
| 112 | @implementation S |
| 113 | @end |