Fariborz Jahanian | 975eef6 | 2012-05-03 16:43:30 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -fobjc-default-synthesize-properties -Wobjc-missing-property-synthesis -verify -Wno-objc-root-class %s |
| 2 | // rdar://11295716 |
Fariborz Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 3 | |
| 4 | @interface NSObject |
| 5 | - (void) release; |
| 6 | - (id) retain; |
| 7 | @end |
| 8 | @class NSString; |
| 9 | |
| 10 | @interface SynthItAll : NSObject |
Fariborz Jahanian | 975eef6 | 2012-05-03 16:43:30 +0000 | [diff] [blame] | 11 | @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 Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 13 | @end |
| 14 | |
Fariborz Jahanian | 975eef6 | 2012-05-03 16:43:30 +0000 | [diff] [blame] | 15 | @implementation SynthItAll // expected-note 2 {{detected while default synthesizing properties in class implementation}} |
Fariborz Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 16 | //@synthesize howMany, what; |
| 17 | @end |
| 18 | |
| 19 | |
| 20 | @interface SynthSetter : NSObject |
Fariborz Jahanian | 975eef6 | 2012-05-03 16:43:30 +0000 | [diff] [blame] | 21 | @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 Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 23 | @end |
| 24 | |
Fariborz Jahanian | 975eef6 | 2012-05-03 16:43:30 +0000 | [diff] [blame] | 25 | @implementation SynthSetter // expected-note 2 {{detected while default synthesizing properties in class implementation}} |
Fariborz Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 26 | //@synthesize howMany, what; |
| 27 | |
| 28 | - (int) howMany { |
Ted Kremenek | d2ee809 | 2011-09-27 23:39:40 +0000 | [diff] [blame] | 29 | return _howMany; |
Fariborz Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 30 | } |
| 31 | // - (void) setHowMany: (int) value |
| 32 | |
| 33 | - (NSString*) what { |
Ted Kremenek | d2ee809 | 2011-09-27 23:39:40 +0000 | [diff] [blame] | 34 | return _what; |
Fariborz Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 35 | } |
| 36 | // - (void) setWhat: (NSString*) value |
| 37 | @end |
| 38 | |
| 39 | |
| 40 | @interface SynthGetter : NSObject |
Fariborz Jahanian | 975eef6 | 2012-05-03 16:43:30 +0000 | [diff] [blame] | 41 | @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 Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 43 | @end |
| 44 | |
Fariborz Jahanian | 975eef6 | 2012-05-03 16:43:30 +0000 | [diff] [blame] | 45 | @implementation SynthGetter // expected-note 2 {{detected while default synthesizing properties in class implementation}} |
Fariborz Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 46 | //@synthesize howMany, what; |
| 47 | |
| 48 | // - (int) howMany |
| 49 | - (void) setHowMany: (int) value { |
Ted Kremenek | d2ee809 | 2011-09-27 23:39:40 +0000 | [diff] [blame] | 50 | _howMany = value; |
Fariborz Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // - (NSString*) what |
| 54 | - (void) setWhat: (NSString*) value { |
Ted Kremenek | d2ee809 | 2011-09-27 23:39:40 +0000 | [diff] [blame] | 55 | if (_what != value) { |
| 56 | [_what release]; |
| 57 | _what = [value retain]; |
Fariborz Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 58 | } |
| 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 Jahanian | 8697d30 | 2011-08-31 22:24:06 +0000 | [diff] [blame] | 72 | return howMany; // expected-error {{use of undeclared identifier 'howMany'}} |
Fariborz Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 73 | } |
| 74 | - (void) setHowMany: (int) value { |
Fariborz Jahanian | 8697d30 | 2011-08-31 22:24:06 +0000 | [diff] [blame] | 75 | howMany = value; // expected-error {{use of undeclared identifier 'howMany'}} |
Fariborz Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | - (NSString*) what { |
Fariborz Jahanian | 8697d30 | 2011-08-31 22:24:06 +0000 | [diff] [blame] | 79 | return what; // expected-error {{use of undeclared identifier 'what'}} |
Fariborz Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 80 | } |
| 81 | - (void) setWhat: (NSString*) value { |
Fariborz Jahanian | 8697d30 | 2011-08-31 22:24:06 +0000 | [diff] [blame] | 82 | 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 Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | @end |
| 88 | |
Fariborz Jahanian | 95f1b86 | 2010-08-25 00:31:58 +0000 | [diff] [blame] | 89 | // 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 Jahanian | af6c314 | 2010-07-17 01:16:59 +0000 | [diff] [blame] | 117 | |
Eli Friedman | e4c043d | 2012-05-01 22:26:06 +0000 | [diff] [blame] | 118 | @interface rdar11333367 |
| 119 | @property enum A x; // expected-note {{forward declaration of 'enum A'}} expected-note {{property declared here}} |
Fariborz Jahanian | 975eef6 | 2012-05-03 16:43:30 +0000 | [diff] [blame] | 120 | @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 Friedman | e4c043d | 2012-05-01 22:26:06 +0000 | [diff] [blame] | 122 | @end |
Fariborz Jahanian | 975eef6 | 2012-05-03 16:43:30 +0000 | [diff] [blame] | 123 | @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 Friedman | e4c043d | 2012-05-01 22:26:06 +0000 | [diff] [blame] | 125 | @synthesize x; // expected-error {{cannot synthesize property 'x' with incomplete type 'enum A'}} |
| 126 | @end |