Rafael Espindola | 14f9889 | 2013-09-27 20:21:48 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2 | // rdar://9340606 |
| 3 | |
| 4 | @interface Foo { |
| 5 | @public |
Argyrios Kyrtzidis | 135aa60 | 2012-12-12 22:48:25 +0000 | [diff] [blame] | 6 | id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}} |
| 7 | id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}} |
Fariborz Jahanian | 9b760e8 | 2012-09-24 22:51:51 +0000 | [diff] [blame] | 8 | id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9 | } |
| 10 | @property(strong) id x; // expected-note {{property declared here}} |
| 11 | @property(strong) id y; // expected-note {{property declared here}} |
| 12 | @property(strong) id z; |
| 13 | @end |
| 14 | |
| 15 | @implementation Foo |
Argyrios Kyrtzidis | 135aa60 | 2012-12-12 22:48:25 +0000 | [diff] [blame] | 16 | @synthesize x; // expected-note {{property synthesized here}} |
| 17 | @synthesize y; // expected-note {{property synthesized here}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 18 | @synthesize z; // suppressed |
| 19 | @end |
| 20 | |
| 21 | @interface Bar { |
| 22 | @public |
Argyrios Kyrtzidis | 135aa60 | 2012-12-12 22:48:25 +0000 | [diff] [blame] | 23 | id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}} |
| 24 | id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}} |
Fariborz Jahanian | 9b760e8 | 2012-09-24 22:51:51 +0000 | [diff] [blame] | 25 | id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 26 | } |
| 27 | @property(retain) id x; // expected-note {{property declared here}} |
| 28 | @property(retain) id y; // expected-note {{property declared here}} |
| 29 | @property(retain) id z; |
| 30 | @end |
| 31 | |
| 32 | @implementation Bar |
Argyrios Kyrtzidis | 135aa60 | 2012-12-12 22:48:25 +0000 | [diff] [blame] | 33 | @synthesize x; // expected-note {{property synthesized here}} |
| 34 | @synthesize y; // expected-note {{property synthesized here}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 35 | @synthesize z; // suppressed |
| 36 | @end |
| 37 | |
| 38 | @interface Bas { |
| 39 | @public |
Argyrios Kyrtzidis | 135aa60 | 2012-12-12 22:48:25 +0000 | [diff] [blame] | 40 | id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}} |
| 41 | id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}} |
Fariborz Jahanian | 9b760e8 | 2012-09-24 22:51:51 +0000 | [diff] [blame] | 42 | id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 43 | } |
| 44 | @property(copy) id x; // expected-note {{property declared here}} |
| 45 | @property(copy) id y; // expected-note {{property declared here}} |
| 46 | @property(copy) id z; |
| 47 | @end |
| 48 | |
| 49 | @implementation Bas |
Argyrios Kyrtzidis | 135aa60 | 2012-12-12 22:48:25 +0000 | [diff] [blame] | 50 | @synthesize x; // expected-note {{property synthesized here}} |
| 51 | @synthesize y; // expected-note {{property synthesized here}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 52 | @synthesize z; // suppressed |
| 53 | @end |
| 54 | |
| 55 | @interface Bat |
| 56 | @property(strong) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} |
| 57 | @property(strong) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} |
| 58 | @end |
| 59 | |
| 60 | @interface Bau |
| 61 | @property(retain) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} |
| 62 | @property(retain) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} |
| 63 | @end |
| 64 | |
| 65 | @interface Bav |
| 66 | @property(copy) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} |
| 67 | @property(copy) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} |
| 68 | @end |
| 69 | |
| 70 | // rdar://9341593 |
| 71 | @interface Gorf { |
| 72 | id __unsafe_unretained x; |
Argyrios Kyrtzidis | 135aa60 | 2012-12-12 22:48:25 +0000 | [diff] [blame] | 73 | id y; // expected-error {{existing instance variable 'y' for property 'y' with assign attribute must be __unsafe_unretained}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 74 | } |
| 75 | @property(assign) id __unsafe_unretained x; |
| 76 | @property(assign) id y; // expected-note {{property declared here}} |
| 77 | @property(assign) id z; |
| 78 | @end |
| 79 | |
| 80 | @implementation Gorf |
| 81 | @synthesize x; |
Argyrios Kyrtzidis | 135aa60 | 2012-12-12 22:48:25 +0000 | [diff] [blame] | 82 | @synthesize y; // expected-note {{property synthesized here}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 83 | @synthesize z; |
| 84 | @end |
| 85 | |
| 86 | @interface Gorf2 { |
| 87 | id __unsafe_unretained x; |
Argyrios Kyrtzidis | 135aa60 | 2012-12-12 22:48:25 +0000 | [diff] [blame] | 88 | id y; // expected-error {{existing instance variable 'y' for property 'y' with unsafe_unretained attribute must be __unsafe_unretained}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 89 | } |
| 90 | @property(unsafe_unretained) id __unsafe_unretained x; |
| 91 | @property(unsafe_unretained) id y; // expected-note {{property declared here}} |
| 92 | @property(unsafe_unretained) id z; |
| 93 | @end |
| 94 | |
| 95 | @implementation Gorf2 |
| 96 | @synthesize x; |
Argyrios Kyrtzidis | 135aa60 | 2012-12-12 22:48:25 +0000 | [diff] [blame] | 97 | @synthesize y; // expected-note {{property synthesized here}} |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 98 | @synthesize z; |
| 99 | @end |
| 100 | |
| 101 | // rdar://9355230 |
| 102 | @interface I { |
| 103 | char _isAutosaving; |
| 104 | } |
| 105 | @property char isAutosaving; |
| 106 | |
| 107 | @end |
| 108 | |
| 109 | @implementation I |
| 110 | @synthesize isAutosaving = _isAutosaving; |
| 111 | @end |
| 112 | |
Fariborz Jahanian | 5fa065b | 2011-10-13 23:45:45 +0000 | [diff] [blame] | 113 | // rdar://10239594 |
| 114 | // Test for 'Class' properties being unretained. |
| 115 | @interface MyClass { |
| 116 | @private |
| 117 | Class _controllerClass; |
| 118 | id _controllerId; |
| 119 | } |
| 120 | @property (copy) Class controllerClass; |
| 121 | @property (copy) id controllerId; |
| 122 | @end |
| 123 | |
| 124 | @implementation MyClass |
| 125 | @synthesize controllerClass = _controllerClass; |
| 126 | @synthesize controllerId = _controllerId; |
| 127 | @end |
Fariborz Jahanian | 6e6f93a | 2012-01-10 19:28:26 +0000 | [diff] [blame] | 128 | |
| 129 | // rdar://10630891 |
| 130 | @interface UIView @end |
| 131 | @class UIColor; |
| 132 | |
| 133 | @interface UIView(UIViewRendering) |
| 134 | @property(nonatomic,copy) UIColor *backgroundColor; |
| 135 | @end |
| 136 | |
| 137 | @interface UILabel : UIView |
| 138 | @end |
| 139 | |
| 140 | @interface MyView |
| 141 | @property (strong) UILabel *label; |
| 142 | @end |
| 143 | |
| 144 | @interface MyView2 : MyView @end |
| 145 | |
| 146 | @implementation MyView2 |
| 147 | - (void)foo { |
| 148 | super.label.backgroundColor = 0; |
| 149 | } |
| 150 | @end |
| 151 | |
Fariborz Jahanian | 87eaf72 | 2012-01-17 22:58:16 +0000 | [diff] [blame] | 152 | // rdar://10694932 |
| 153 | @interface Baz |
| 154 | @property id prop; |
| 155 | @property __strong id strong_prop; |
| 156 | @property (strong) id strong_attr_prop; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame^] | 157 | @property (strong) __strong id really_strong_attr_prop; |
Fariborz Jahanian | 87eaf72 | 2012-01-17 22:58:16 +0000 | [diff] [blame] | 158 | + (id) alloc; |
| 159 | - (id) init; |
| 160 | - (id) implicit; |
| 161 | - (void) setImplicit : (id) arg; |
| 162 | @end |
| 163 | |
| 164 | void foo(Baz *f) { |
| 165 | f.prop = [[Baz alloc] init]; |
| 166 | f.strong_prop = [[Baz alloc] init]; |
| 167 | f.strong_attr_prop = [[Baz alloc] init]; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame^] | 168 | f.really_strong_attr_prop = [[Baz alloc] init]; |
Fariborz Jahanian | 87eaf72 | 2012-01-17 22:58:16 +0000 | [diff] [blame] | 169 | f.implicit = [[Baz alloc] init]; |
| 170 | } |
Fariborz Jahanian | 0e78afb | 2012-04-20 22:00:46 +0000 | [diff] [blame] | 171 | |
| 172 | // rdar://11253688 |
| 173 | @interface Boom |
Fariborz Jahanian | 937ec1d | 2013-09-19 16:37:20 +0000 | [diff] [blame] | 174 | { |
| 175 | const void * innerPointerIvar __attribute__((objc_returns_inner_pointer)); // expected-error {{'objc_returns_inner_pointer' attribute only applies to methods and properties}} |
| 176 | } |
Fariborz Jahanian | f35a356 | 2013-09-19 17:18:55 +0000 | [diff] [blame] | 177 | @property (readonly) Boom * NotInnerPointer __attribute__((objc_returns_inner_pointer)); // expected-warning {{'objc_returns_inner_pointer' attribute only applies to properties that return a non-retainable pointer}} |
| 178 | - (Boom *) NotInnerPointerMethod __attribute__((objc_returns_inner_pointer)); // expected-warning {{'objc_returns_inner_pointer' attribute only applies to methods that return a non-retainable pointer}} |
Fariborz Jahanian | 937ec1d | 2013-09-19 16:37:20 +0000 | [diff] [blame] | 179 | @property (readonly) const void * innerPointer __attribute__((objc_returns_inner_pointer)); |
Fariborz Jahanian | 0e78afb | 2012-04-20 22:00:46 +0000 | [diff] [blame] | 180 | @end |
Argyrios Kyrtzidis | 135aa60 | 2012-12-12 22:48:25 +0000 | [diff] [blame] | 181 | |
| 182 | @interface Foo2 { |
| 183 | id _prop; // expected-error {{existing instance variable '_prop' for property 'prop' with assign attribute must be __unsafe_unretained}} |
| 184 | } |
| 185 | @property (nonatomic, assign) id prop; // expected-note {{property declared here}} |
| 186 | @end |
| 187 | |
| 188 | @implementation Foo2 |
| 189 | @end |
Fariborz Jahanian | b8ed071 | 2013-05-16 19:08:44 +0000 | [diff] [blame] | 190 | |
| 191 | // rdar://13885083 |
| 192 | @interface NSObject |
| 193 | -(id)init; |
| 194 | @end |
| 195 | |
| 196 | typedef char BOOL; |
| 197 | @interface Test13885083 : NSObject |
| 198 | |
| 199 | @property (nonatomic, assign) BOOL retain; // expected-error {{ARC forbids synthesis of 'retain'}} |
| 200 | |
| 201 | -(id)init; |
| 202 | |
| 203 | @end |
| 204 | |
| 205 | @implementation Test13885083 |
| 206 | -(id) init |
| 207 | { |
| 208 | self = [super init]; |
| 209 | return self; |
| 210 | } |
| 211 | @end |
| 212 | |