xref: /aosp_15_r20/external/clang/test/SemaObjC/arc-property.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -fobjc-exceptions -verify -Wno-objc-root-class %s
2*67e74705SXin Li// rdar://9309489
3*67e74705SXin Li
4*67e74705SXin Li@interface MyClass {
5*67e74705SXin Li        id __weak myString; // expected-error {{existing instance variable 'myString' for strong property 'myString' may not be __weak}}
6*67e74705SXin Li        id StrongIvar;
7*67e74705SXin Li        id __weak myString2; // expected-error {{existing instance variable 'myString2' for strong property 'myString2' may not be __weak}}
8*67e74705SXin Li        id __weak myString3;
9*67e74705SXin Li        id StrongIvar5; // expected-error {{existing instance variable 'StrongIvar5' for __weak property 'myString5' must be __weak}}
10*67e74705SXin Li}
11*67e74705SXin Li@property (strong) id myString; // expected-note {{property declared here}}
12*67e74705SXin Li@property (strong) id myString1;
13*67e74705SXin Li@property (retain) id myString2; // expected-note {{property declared here}}
14*67e74705SXin Li//
15*67e74705SXin Li@property (weak) id myString3;
16*67e74705SXin Li@property (weak) id myString4;
17*67e74705SXin Li@property __weak id myString5; // expected-note {{property declared here}}
18*67e74705SXin Li@end
19*67e74705SXin Li
20*67e74705SXin Li@implementation MyClass
21*67e74705SXin Li@synthesize myString; // expected-note {{property synthesized here}}
22*67e74705SXin Li@synthesize myString1 = StrongIvar; // OK
23*67e74705SXin Li@synthesize myString2 = myString2; // expected-note {{property synthesized here}}
24*67e74705SXin Li//
25*67e74705SXin Li@synthesize myString3; // OK
26*67e74705SXin Li@synthesize myString4; // OK
27*67e74705SXin Li@synthesize myString5 = StrongIvar5; // expected-note {{property synthesized here}}
28*67e74705SXin Li
29*67e74705SXin Li@end
30*67e74705SXin Li
31*67e74705SXin Li// rdar://9340692
32*67e74705SXin Li@interface Foo {
33*67e74705SXin Li@public
34*67e74705SXin Li    id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}}
35*67e74705SXin Li    id __strong y;  // expected-error {{existing instance variable 'y' for __weak property 'y' must be __weak}}
36*67e74705SXin Li    id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
37*67e74705SXin Li}
38*67e74705SXin Li@property(weak) id x; // expected-note {{property declared here}}
39*67e74705SXin Li@property(weak) id y; // expected-note {{property declared here}}
40*67e74705SXin Li@property(weak) id z;
41*67e74705SXin Li@end
42*67e74705SXin Li
43*67e74705SXin Li@implementation Foo
44*67e74705SXin Li@synthesize x; // expected-note {{property synthesized here}}
45*67e74705SXin Li@synthesize y; // expected-note {{property synthesized here}}
46*67e74705SXin Li@synthesize z;  // suppressed
47*67e74705SXin Li@end
48*67e74705SXin Li
49*67e74705SXin Li// rdar://problem/10904479
50*67e74705SXin Li// Don't crash.
51*67e74705SXin Li@interface Test2
52*67e74705SXin Li// Minor FIXME: kill the redundant error
53*67e74705SXin Li@property (strong) UndeclaredClass *test2;  // expected-error {{unknown type name 'UndeclaredClass'}} expected-error {{must be of object type}}
54*67e74705SXin Li@end
55*67e74705SXin Li@implementation Test2
56*67e74705SXin Li@synthesize test2;
57*67e74705SXin Li@end
58*67e74705SXin Li
59*67e74705SXin Li// rdar://problem/11144407
60*67e74705SXin Li@interface Test3
61*67e74705SXin Li@property (strong) id exception;
62*67e74705SXin Li@end
63*67e74705SXin Livoid test3(Test3 *t3) {
64*67e74705SXin Li  @throw t3.exception;
65*67e74705SXin Li}
66