1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s
5 id __unsafe_unretained x;
7 id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
9 @property(strong) id x;
10 @property(strong) id y;
11 @property(strong) id z;
16 id __unsafe_unretained x;
18 id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
20 @property(retain) id x;
21 @property(retain) id y;
22 @property(retain) id z;
27 id __unsafe_unretained x;
29 id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
36 // Errors should start about here :-)
39 @property(strong) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}}
40 @property(strong) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}}
41 @property(strong) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}}
45 @property(retain) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}}
46 @property(retain) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}}
47 @property(retain) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}}
51 @property(copy) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}}
52 @property(copy) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}}
53 @property(copy) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}}
57 @property(assign) __unsafe_unretained id x;
58 @property(assign) __weak id y; // expected-error {{unsafe_unretained property 'y' may not also be declared __weak}}
59 @property(assign) __autoreleasing id z; // expected-error {{unsafe_unretained property 'z' may not also be declared __autoreleasing}}
63 @property(unsafe_unretained) __unsafe_unretained id x;
64 @property(unsafe_unretained) __weak id y; // expected-error {{unsafe_unretained property 'y' may not also be declared __weak}}
65 @property(unsafe_unretained) __autoreleasing id z; // expected-error {{unsafe_unretained property 'z' may not also be declared __autoreleasing}}
69 @property (readonly, retain) id foo;
70 @property (readonly, weak) id fee;
71 @property (readonly, strong) id frr;
74 @interface Bugg : Super
75 @property (readwrite) id foo;
76 @property (readwrite) id fee;
77 @property (readwrite) id frr;
80 @interface NSObject @end
82 #pragma clang assume_nonnull begin
83 @interface I: NSObject
84 @property(nonatomic, weak) id delegate; // Do not warn, nullable is inferred.
85 @property(nonatomic, weak, readonly) id ROdelegate; // Do not warn, nullable is inferred.
86 @property(nonatomic, weak, nonnull) id NonNulldelete; // expected-error {{property attributes 'nonnull' and 'weak' are mutually exclusive}}
87 @property(nonatomic, weak, nullable) id Nullabledelete; // do not warn
90 @property(nonatomic, strong) id stdelegate; // Do not warn
91 @property(nonatomic, readonly) id stROdelegate; // Do not warn
92 @property(nonatomic, strong, nonnull) id stNonNulldelete; // Do not warn
93 @property(nonatomic, nullable) id stNullabledelete; // do not warn
95 #pragma clang assume_nonnull end
97 @interface J: NSObject
98 @property(nonatomic, weak) id ddd; // Do not warn, nullable is inferred.
99 @property(nonatomic, weak, nonnull) id delegate; // expected-error {{property attributes 'nonnull' and 'weak' are mutually exclusive}}
100 @property(nonatomic, weak, nonnull, readonly) id ROdelegate; // expected-error {{property attributes 'nonnull' and 'weak' are mutually exclusive}}
104 @property(readonly, retain) id prop;
107 __attribute__((objc_root_class))
112 @property (readwrite) id prop;
119 // Verify that the all of the property declarations in inherited protocols are
120 // compatible when synthesing a property from a protocol.
122 @protocol CopyVsAssign1
123 @property (copy, nonatomic, readonly) id prop; // expected-error {{property with attribute 'copy' was selected for synthesis}}
125 @protocol CopyVsAssign2
126 @property (assign, nonatomic, readonly) id prop; // expected-note {{it could also be property without attribute 'copy' declared here}}
129 @interface CopyVsAssign: Foo <CopyVsAssign1, CopyVsAssign2>
131 @implementation CopyVsAssign
132 @synthesize prop; // expected-note {{property synthesized here}}
135 @protocol RetainVsNonRetain1
136 @property (readonly) id prop; // expected-error {{property without attribute 'retain (or strong)' was selected for synthesis}}
138 @protocol RetainVsNonRetain2
139 @property (retain, readonly) id prop; // expected-note {{it could also be property with attribute 'retain (or strong)' declared here}}
142 @interface RetainVsNonRetain: Foo <RetainVsNonRetain1, RetainVsNonRetain2>
144 @implementation RetainVsNonRetain
145 @synthesize prop; // expected-note {{property synthesized here}}
148 @protocol AtomicVsNonatomic1
149 @property (copy, nonatomic, readonly) id prop; // expected-error {{property without attribute 'atomic' was selected for synthesis}}
151 @protocol AtomicVsNonatomic2
152 @property (copy, atomic, readonly) id prop; // expected-note {{it could also be property with attribute 'atomic' declared here}}
155 @interface AtomicVsNonAtomic: Foo <AtomicVsNonatomic1, AtomicVsNonatomic2>
157 @implementation AtomicVsNonAtomic
158 @synthesize prop; // expected-note {{property synthesized here}}
162 @property (copy, readonly) id prop; // expected-error {{property with getter 'prop' was selected for synthesis}}
165 @property (copy, getter=x, readonly) id prop; // expected-note {{it could also be property with getter 'x' declared here}}
168 @interface GetterVsGetter: Foo <Getter1, Getter2>
170 @implementation GetterVsGetter
171 @synthesize prop; // expected-note {{property synthesized here}}
175 @property (copy, readonly) id prop;
178 @property (copy, setter=setp:, readwrite) id prop; // expected-error {{property with setter 'setp:' was selected for synthesis}}
181 @property (copy, readwrite) id prop; // expected-note {{it could also be property with setter 'setProp:' declared here}}
184 @interface SetterVsSetter: Foo <Setter1, Setter2, Setter3>
186 @implementation SetterVsSetter
187 @synthesize prop; // expected-note {{property synthesized here}}
190 @protocol TypeVsAttribute1
191 @property (assign, atomic, readonly) int prop; // expected-error {{property of type 'int' was selected for synthesis}}
193 @protocol TypeVsAttribute2
194 @property (assign, atomic, readonly) id prop; // expected-note {{it could also be property of type 'id' declared here}}
196 @protocol TypeVsAttribute3
197 @property (copy, readonly) id prop; // expected-note {{it could also be property with attribute 'copy' declared here}}
200 @interface TypeVsAttribute: Foo <TypeVsAttribute1, TypeVsAttribute2, TypeVsAttribute3>
202 @implementation TypeVsAttribute
203 @synthesize prop; // expected-note {{property synthesized here}}
206 @protocol TypeVsSetter1
207 @property (assign, nonatomic, readonly) int prop; // expected-note {{it could also be property of type 'int' declared here}}
209 @protocol TypeVsSetter2
210 @property (assign, nonatomic, readonly) id prop; // ok
212 @protocol TypeVsSetter3
213 @property (assign, nonatomic, readwrite) id prop; // expected-error {{property of type 'id' was selected for synthesis}}
216 @interface TypeVsSetter: Foo <TypeVsSetter1, TypeVsSetter2, TypeVsSetter3>
218 @implementation TypeVsSetter
219 @synthesize prop; // expected-note {{property synthesized here}}
222 @protocol AutoStrongProp
224 @property (nonatomic, readonly) NSObject *prop;
228 @protocol AutoStrongProp_Internal <AutoStrongProp>
230 // This property gets the 'strong' attribute automatically.
231 @property (nonatomic, readwrite) NSObject *prop;
235 @interface SynthesizeWithImplicitStrongNoError : NSObject <AutoStrongProp>
238 @interface SynthesizeWithImplicitStrongNoError () <AutoStrongProp_Internal>
242 @implementation SynthesizeWithImplicitStrongNoError
244 // no error, 'strong' is implicit in the 'readwrite' property.
245 @synthesize prop = _prop;
249 // Allow strong readwrite property and a readonly one.
250 @protocol StrongCollision
252 @property(strong) NSObject *p;
253 @property(copy) NSObject *p2;
255 // expected-error@+1 {{property with attribute 'retain (or strong)' was selected for synthesis}}
256 @property(strong, readwrite) NSObject *collision;
260 @protocol ReadonlyCollision
262 @property(readonly) NSObject *p;
263 @property(readonly) NSObject *p2;
265 // expected-note@+1 {{it could also be property without attribute 'retain (or strong)' declared here}}
266 @property(readonly, weak) NSObject *collision;
270 @interface StrongReadonlyCollision : NSObject <StrongCollision, ReadonlyCollision>
273 @implementation StrongReadonlyCollision
277 @synthesize p2 = _p2;
279 @synthesize collision = _collision; // expected-note {{property synthesized here}}
283 // This used to crash because we'd temporarly store the weak attribute on the
284 // declaration specifier, then deallocate it when clearing the declarator.
285 id i1, __weak i2, i3;