xref: /aosp_15_r20/external/clang/test/SemaObjC/property.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -triple i386-apple-darwin9 -fobjc-runtime=macosx-fragile-10.5 -fsyntax-only -verify -Wno-objc-root-class %s
2*67e74705SXin Li
3*67e74705SXin Li@interface I
4*67e74705SXin Li{
5*67e74705SXin Li	int IVAR; // expected-note{{instance variable is declared here}}
6*67e74705SXin Li	int name;
7*67e74705SXin Li}
8*67e74705SXin Li@property int d1;
9*67e74705SXin Li@property id  prop_id; // expected-warning {{no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed}}, expected-warning {{default property attribute 'assign' not appropriate for non-GC object}}
10*67e74705SXin Li@property int name;
11*67e74705SXin Li@end
12*67e74705SXin Li
13*67e74705SXin Li@interface I(CAT)
14*67e74705SXin Li@property int d1;
15*67e74705SXin Li@end
16*67e74705SXin Li
17*67e74705SXin Li@implementation I
18*67e74705SXin Li@synthesize d1;		// expected-error {{synthesized property 'd1' must either be named the same as}}
19*67e74705SXin Li@dynamic    bad;	// expected-error {{property implementation must have its declaration in interface 'I'}}
20*67e74705SXin Li@synthesize prop_id;	// expected-error {{synthesized property 'prop_id' must either be named the same}}  // expected-note {{previous declaration is here}}
21*67e74705SXin Li@synthesize prop_id = IVAR;	// expected-error {{type of property 'prop_id' ('id') does not match type of instance variable 'IVAR' ('int')}} // expected-error {{property 'prop_id' is already implemented}}
22*67e74705SXin Li@synthesize name;	// OK! property with same name as an accessible ivar of same name
23*67e74705SXin Li@end
24*67e74705SXin Li
25*67e74705SXin Li@implementation I(CAT)
26*67e74705SXin Li@synthesize d1;		// expected-error {{@synthesize not allowed in a category's implementation}}
27*67e74705SXin Li@dynamic bad;		// expected-error {{property implementation must have its declaration in the category 'CAT'}}
28*67e74705SXin Li@end
29*67e74705SXin Li
30*67e74705SXin Li@implementation E	// expected-warning {{cannot find interface declaration for 'E'}}
31*67e74705SXin Li@dynamic d;		// expected-error {{property implementation must have its declaration in interface 'E'}}
32*67e74705SXin Li@end
33*67e74705SXin Li
34*67e74705SXin Li@implementation Q(MYCAT)  // expected-error {{cannot find interface declaration for 'Q'}}
35*67e74705SXin Li@dynamic d;		// expected-error {{property implementation in a category with no category declaration}}
36*67e74705SXin Li@end
37*67e74705SXin Li
38*67e74705SXin Li@interface Foo
39*67e74705SXin Li@property double bar;
40*67e74705SXin Li@end
41*67e74705SXin Li
42*67e74705SXin Liint func1() {
43*67e74705SXin Li   id foo;
44*67e74705SXin Li   double bar = [foo bar];
45*67e74705SXin Li   return 0;
46*67e74705SXin Li}
47*67e74705SXin Li
48*67e74705SXin Li// PR3932
49*67e74705SXin Litypedef id BYObjectIdentifier;
50*67e74705SXin Li@interface Foo1  {
51*67e74705SXin Li  void *isa;
52*67e74705SXin Li}
53*67e74705SXin Li@property(copy) BYObjectIdentifier identifier;
54*67e74705SXin Li@end
55*67e74705SXin Li
56*67e74705SXin Li@interface Foo2
57*67e74705SXin Li{
58*67e74705SXin Li  int ivar;
59*67e74705SXin Li}
60*67e74705SXin Li@property int treeController;  // expected-note {{property declared here}}
61*67e74705SXin Li@property int ivar;	// OK
62*67e74705SXin Li@property int treeController;  // expected-error {{property has a previous declaration}}
63*67e74705SXin Li@end
64*67e74705SXin Li
65*67e74705SXin Li// rdar://10127639
66*67e74705SXin Li@synthesize window; // expected-error {{missing context for property implementation declaration}}
67*67e74705SXin Li
68*67e74705SXin Li// rdar://10408414
69*67e74705SXin LiClass test6_getClass();
70*67e74705SXin Li@interface Test6
71*67e74705SXin Li@end
72*67e74705SXin Li@implementation Test6
73*67e74705SXin Li+ (float) globalValue { return 5.0f; }
74*67e74705SXin Li+ (float) gv { return test6_getClass().globalValue; }
75*67e74705SXin Li@end
76*67e74705SXin Li
77*67e74705SXin Li@interface Test7
78*67e74705SXin Li@property unsigned length;
79*67e74705SXin Li@end
80*67e74705SXin Livoid test7(Test7 *t) {
81*67e74705SXin Li  char data[t.length] = {}; // expected-error {{variable-sized object may not be initialized}}
82*67e74705SXin Li}
83