John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i386-apple-darwin9 -fobjc-runtime=macosx-fragile-10.5 -fsyntax-only -verify -Wno-objc-root-class %s |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 2 | |
| 3 | @interface I |
| 4 | { |
Ted Kremenek | f921a48 | 2010-03-23 19:02:22 +0000 | [diff] [blame] | 5 | int IVAR; // expected-note{{ivar is declared here}} |
Fariborz Jahanian | 6cdf16d | 2008-04-21 21:57:36 +0000 | [diff] [blame] | 6 | int name; |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 7 | } |
| 8 | @property int d1; |
Ted Kremenek | 08c88db | 2012-05-01 05:56:02 +0000 | [diff] [blame] | 9 | @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}} |
Fariborz Jahanian | 6cdf16d | 2008-04-21 21:57:36 +0000 | [diff] [blame] | 10 | @property int name; |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 11 | @end |
| 12 | |
| 13 | @interface I(CAT) |
Fariborz Jahanian | b860739 | 2011-08-27 21:55:47 +0000 | [diff] [blame] | 14 | @property int d1; // expected-note 2 {{property declared here}} |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 15 | @end |
| 16 | |
| 17 | @implementation I |
Fariborz Jahanian | 6cdf16d | 2008-04-21 21:57:36 +0000 | [diff] [blame] | 18 | @synthesize d1; // expected-error {{synthesized property 'd1' must either be named the same as}} |
| 19 | @dynamic bad; // expected-error {{property implementation must have its declaration in interface 'I'}} |
Fariborz Jahanian | 12bac25 | 2009-04-14 23:15:21 +0000 | [diff] [blame] | 20 | @synthesize prop_id; // expected-error {{synthesized property 'prop_id' must either be named the same}} // expected-note {{previous declaration is here}} |
Ted Kremenek | f921a48 | 2010-03-23 19:02:22 +0000 | [diff] [blame] | 21 | @synthesize prop_id = IVAR; // expected-error {{type of property 'prop_id' ('id') does not match type of ivar 'IVAR' ('int')}} // expected-error {{property 'prop_id' is already implemented}} |
Fariborz Jahanian | 6cdf16d | 2008-04-21 21:57:36 +0000 | [diff] [blame] | 22 | @synthesize name; // OK! property with same name as an accessible ivar of same name |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 23 | @end |
| 24 | |
Fariborz Jahanian | b860739 | 2011-08-27 21:55:47 +0000 | [diff] [blame] | 25 | @implementation I(CAT) // expected-warning {{property 'd1' requires method 'd1' to be defined }} \ |
| 26 | // expected-warning {{property 'd1' requires method 'setD1:' to be defined }} |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 27 | @synthesize d1; // expected-error {{@synthesize not allowed in a category's implementation}} |
| 28 | @dynamic bad; // expected-error {{property implementation must have its declaration in the category 'CAT'}} |
| 29 | @end |
| 30 | |
| 31 | @implementation E // expected-warning {{cannot find interface declaration for 'E'}} |
Fariborz Jahanian | 6cdf16d | 2008-04-21 21:57:36 +0000 | [diff] [blame] | 32 | @dynamic d; // expected-error {{property implementation must have its declaration in interface 'E'}} |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 33 | @end |
| 34 | |
| 35 | @implementation Q(MYCAT) // expected-error {{cannot find interface declaration for 'Q'}} |
| 36 | @dynamic d; // expected-error {{property implementation in a category with no category declaration}} |
| 37 | @end |
| 38 | |
Steve Naroff | 5e0a74f | 2008-09-29 14:20:56 +0000 | [diff] [blame] | 39 | @interface Foo |
| 40 | @property double bar; |
| 41 | @end |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 42 | |
Chris Lattner | 16ede0e | 2009-04-12 23:51:02 +0000 | [diff] [blame] | 43 | int func1() { |
Steve Naroff | 5e0a74f | 2008-09-29 14:20:56 +0000 | [diff] [blame] | 44 | id foo; |
| 45 | double bar = [foo bar]; |
| 46 | return 0; |
| 47 | } |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 16ede0e | 2009-04-12 23:51:02 +0000 | [diff] [blame] | 49 | // PR3932 |
| 50 | typedef id BYObjectIdentifier; |
| 51 | @interface Foo1 { |
| 52 | void *isa; |
| 53 | } |
| 54 | @property(copy) BYObjectIdentifier identifier; |
| 55 | @end |
| 56 | |
Fariborz Jahanian | 6dd30fc | 2009-12-17 00:49:09 +0000 | [diff] [blame] | 57 | @interface Foo2 |
| 58 | { |
| 59 | int ivar; |
| 60 | } |
| 61 | @property int treeController; // expected-note {{property declared here}} |
| 62 | @property int ivar; // OK |
| 63 | @property int treeController; // expected-error {{property has a previous declaration}} |
| 64 | @end |
| 65 | |
Fariborz Jahanian | 898f284 | 2011-09-17 18:48:50 +0000 | [diff] [blame] | 66 | // rdar://10127639 |
| 67 | @synthesize window; // expected-error {{missing context for property implementation declaration}} |
John McCall | dc4df51 | 2011-11-07 22:49:50 +0000 | [diff] [blame] | 68 | |
| 69 | // rdar://10408414 |
| 70 | Class test6_getClass(); |
| 71 | @interface Test6 |
| 72 | @end |
| 73 | @implementation Test6 |
| 74 | + (float) globalValue { return 5.0f; } |
| 75 | + (float) gv { return test6_getClass().globalValue; } |
| 76 | @end |
John McCall | 806054d | 2012-01-11 00:14:46 +0000 | [diff] [blame] | 77 | |
| 78 | @interface Test7 |
| 79 | @property unsigned length; |
| 80 | @end |
| 81 | void test7(Test7 *t) { |
| 82 | char data[t.length] = {}; // expected-error {{variable-sized object may not be initialized}} |
| 83 | } |