xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjC/property-13.m (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code
2*f4a2713aSLionel Sambuc// expected-no-diagnostics
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc@interface NSObject
5*f4a2713aSLionel Sambuc+ alloc;
6*f4a2713aSLionel Sambuc- init;
7*f4a2713aSLionel Sambuc@end
8*f4a2713aSLionel Sambuc
9*f4a2713aSLionel Sambuc@protocol Test
10*f4a2713aSLionel Sambuc  @property int required;
11*f4a2713aSLionel Sambuc
12*f4a2713aSLionel Sambuc@optional
13*f4a2713aSLionel Sambuc  @property int optional;
14*f4a2713aSLionel Sambuc  @property int optional1;
15*f4a2713aSLionel Sambuc  @property int optional_preexisting_setter_getter;
16*f4a2713aSLionel Sambuc  @property (setter = setOptional_preexisting_setter_getter: ,
17*f4a2713aSLionel Sambuc	     getter = optional_preexisting_setter_getter) int optional_with_setter_getter_attr;
18*f4a2713aSLionel Sambuc@required
19*f4a2713aSLionel Sambuc  @property int required1;
20*f4a2713aSLionel Sambuc@optional
21*f4a2713aSLionel Sambuc  @property int optional_to_be_defined;
22*f4a2713aSLionel Sambuc  @property (readonly, getter = optional_preexisting_setter_getter) int optional_getter_attr;
23*f4a2713aSLionel Sambuc@end
24*f4a2713aSLionel Sambuc
25*f4a2713aSLionel Sambuc@interface Test : NSObject <Test> {
26*f4a2713aSLionel Sambuc  int ivar;
27*f4a2713aSLionel Sambuc  int ivar1;
28*f4a2713aSLionel Sambuc  int ivar2;
29*f4a2713aSLionel Sambuc}
30*f4a2713aSLionel Sambuc@property int required;
31*f4a2713aSLionel Sambuc@property int optional_to_be_defined;
32*f4a2713aSLionel Sambuc- (int) optional_preexisting_setter_getter;
33*f4a2713aSLionel Sambuc- (void) setOptional_preexisting_setter_getter:(int)value;
34*f4a2713aSLionel Sambuc@end
35*f4a2713aSLionel Sambuc
36*f4a2713aSLionel Sambuc@implementation Test
37*f4a2713aSLionel Sambuc@synthesize required = ivar;
38*f4a2713aSLionel Sambuc@synthesize required1 = ivar1;
39*f4a2713aSLionel Sambuc@synthesize optional_to_be_defined = ivar2;
40*f4a2713aSLionel Sambuc- (int) optional_preexisting_setter_getter { return ivar; }
41*f4a2713aSLionel Sambuc- (void) setOptional_preexisting_setter_getter:(int)value
42*f4a2713aSLionel Sambuc	   {
43*f4a2713aSLionel Sambuc		ivar = value;
44*f4a2713aSLionel Sambuc	   }
45*f4a2713aSLionel Sambuc- (void) setOptional_getter_attr:(int)value { ivar = value; }
46*f4a2713aSLionel Sambuc@end
47*f4a2713aSLionel Sambuc
48*f4a2713aSLionel Sambucvoid abort(void);
49*f4a2713aSLionel Sambucint main ()
50*f4a2713aSLionel Sambuc{
51*f4a2713aSLionel Sambuc	Test *x = [[Test alloc] init];
52*f4a2713aSLionel Sambuc	/* 1. Test of a required property */
53*f4a2713aSLionel Sambuc	x.required1 = 100;
54*f4a2713aSLionel Sambuc  	if (x.required1 != 100)
55*f4a2713aSLionel Sambuc	  abort ();
56*f4a2713aSLionel Sambuc
57*f4a2713aSLionel Sambuc	/* 2. Test of a synthesize optional property */
58*f4a2713aSLionel Sambuc  	x.optional_to_be_defined = 123;
59*f4a2713aSLionel Sambuc	if (x.optional_to_be_defined != 123)
60*f4a2713aSLionel Sambuc	  abort ();
61*f4a2713aSLionel Sambuc
62*f4a2713aSLionel Sambuc	/* 3. Test of optional property with pre-sxisting defined setter/getter */
63*f4a2713aSLionel Sambuc	x.optional_preexisting_setter_getter = 200;
64*f4a2713aSLionel Sambuc	if (x.optional_preexisting_setter_getter != 200)
65*f4a2713aSLionel Sambuc	  abort ();
66*f4a2713aSLionel Sambuc
67*f4a2713aSLionel Sambuc	/* 4. Test of optional property with setter/getter attribute */
68*f4a2713aSLionel Sambuc	if (x.optional_with_setter_getter_attr != 200)
69*f4a2713aSLionel Sambuc	  abort ();
70*f4a2713aSLionel Sambuc	return 0;
71*f4a2713aSLionel Sambuc
72*f4a2713aSLionel Sambuc	/* 5. Test of optional property with getter attribute and default setter method. */
73*f4a2713aSLionel Sambuc	x.optional_getter_attr = 1000;
74*f4a2713aSLionel Sambuc        if (x.optional_getter_attr != 1000)
75*f4a2713aSLionel Sambuc	  abort ();
76*f4a2713aSLionel Sambuc
77*f4a2713aSLionel Sambuc	return 0;
78*f4a2713aSLionel Sambuc}
79*f4a2713aSLionel Sambuc
80