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