blob: 5aaca9a1c2911e3f4279af0e7fec6d50f171e843 [file] [log] [blame]
Fariborz Jahanian975eef62012-05-03 16:43:30 +00001// RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -Wobjc-missing-property-synthesis -verify -Wno-objc-root-class %s
2// rdar://11295716
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +00003
4@interface NSObject
5- (void) release;
6- (id) retain;
7@end
8@class NSString;
9
10@interface SynthItAll : NSObject
Fariborz Jahanian975eef62012-05-03 16:43:30 +000011@property int howMany; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
12@property (retain) NSString* what; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000013@end
14
Fariborz Jahanian975eef62012-05-03 16:43:30 +000015@implementation SynthItAll // expected-note 2 {{detected while default synthesizing properties in class implementation}}
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000016//@synthesize howMany, what;
17@end
18
19
20@interface SynthSetter : NSObject
Fariborz Jahanian975eef62012-05-03 16:43:30 +000021@property (nonatomic) int howMany; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
22@property (nonatomic, retain) NSString* what; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000023@end
24
Fariborz Jahanian975eef62012-05-03 16:43:30 +000025@implementation SynthSetter // expected-note 2 {{detected while default synthesizing properties in class implementation}}
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000026//@synthesize howMany, what;
27
28- (int) howMany {
Ted Kremenekd2ee8092011-09-27 23:39:40 +000029 return _howMany;
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000030}
31// - (void) setHowMany: (int) value
32
33- (NSString*) what {
Ted Kremenekd2ee8092011-09-27 23:39:40 +000034 return _what;
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000035}
36// - (void) setWhat: (NSString*) value
37@end
38
39
40@interface SynthGetter : NSObject
Fariborz Jahanian975eef62012-05-03 16:43:30 +000041@property (nonatomic) int howMany; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
42@property (nonatomic, retain) NSString* what; // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000043@end
44
Fariborz Jahanian975eef62012-05-03 16:43:30 +000045@implementation SynthGetter // expected-note 2 {{detected while default synthesizing properties in class implementation}}
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000046//@synthesize howMany, what;
47
48// - (int) howMany
49- (void) setHowMany: (int) value {
Ted Kremenekd2ee8092011-09-27 23:39:40 +000050 _howMany = value;
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000051}
52
53// - (NSString*) what
54- (void) setWhat: (NSString*) value {
Ted Kremenekd2ee8092011-09-27 23:39:40 +000055 if (_what != value) {
56 [_what release];
57 _what = [value retain];
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000058 }
59}
60@end
61
62
63@interface SynthNone : NSObject
64@property int howMany;
65@property (retain) NSString* what;
66@end
67
68@implementation SynthNone
69//@synthesize howMany, what; // REM: Redundant anyway
70
71- (int) howMany {
Fariborz Jahanian8697d302011-08-31 22:24:06 +000072 return howMany; // expected-error {{use of undeclared identifier 'howMany'}}
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000073}
74- (void) setHowMany: (int) value {
Fariborz Jahanian8697d302011-08-31 22:24:06 +000075 howMany = value; // expected-error {{use of undeclared identifier 'howMany'}}
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000076}
77
78- (NSString*) what {
Fariborz Jahanian8697d302011-08-31 22:24:06 +000079 return what; // expected-error {{use of undeclared identifier 'what'}}
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000080}
81- (void) setWhat: (NSString*) value {
Fariborz Jahanian8697d302011-08-31 22:24:06 +000082 if (what != value) { // expected-error {{use of undeclared identifier 'what'}}
83 [what release]; // expected-error {{use of undeclared identifier 'what'}}
84 what = [value retain]; // expected-error {{use of undeclared identifier 'what'}}
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +000085 }
86}
87@end
88
Fariborz Jahanian95f1b862010-08-25 00:31:58 +000089// rdar://8349319
90// No default synthesis if implementation has getter (readonly) and setter(readwrite) methods.
91@interface DSATextSearchResult
92@property(assign,readonly) float relevance;
93@property(assign,readonly) char isTitleMatch;
94@end
95
96@interface DSANodeSearchResult : DSATextSearchResult {}
97@end
98
99
100@implementation DSATextSearchResult
101-(char)isTitleMatch {
102 return (char)0;
103}
104
105-(float)relevance {
106 return 0.0;
107}
108@end
109
110@implementation DSANodeSearchResult
111-(id)initWithNode:(id )node relevance:(float)relevance isTitleMatch:(char)isTitleMatch {
112 relevance = 0.0;
113 isTitleMatch = 'a';
114 return self;
115}
116@end
Fariborz Jahanianaf6c3142010-07-17 01:16:59 +0000117
Eli Friedmane4c043d2012-05-01 22:26:06 +0000118@interface rdar11333367
119@property enum A x; // expected-note {{forward declaration of 'enum A'}} expected-note {{property declared here}}
Fariborz Jahanian975eef62012-05-03 16:43:30 +0000120@property struct B y; // expected-note {{forward declaration of 'struct B'}} expected-note {{property declared here}} \
121 // expected-warning {{auto property synthesis is synthesizing property not explicitly synthesized}}
Eli Friedmane4c043d2012-05-01 22:26:06 +0000122@end
Fariborz Jahanian975eef62012-05-03 16:43:30 +0000123@implementation rdar11333367 // expected-error {{cannot synthesize property 'y' with incomplete type 'struct B'}} \
124 // expected-note {{detected while default synthesizing properties in class implementation}}
Eli Friedmane4c043d2012-05-01 22:26:06 +0000125@synthesize x; // expected-error {{cannot synthesize property 'x' with incomplete type 'enum A'}}
126@end