John McCall | 9b0a7ce | 2011-10-02 01:16:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2 | // rdar://9340606 |
| 3 | |
| 4 | @interface Foo { |
| 5 | @public |
| 6 | id __unsafe_unretained x; |
| 7 | id __weak y; |
Fariborz Jahanian | 61740f6 | 2012-09-24 22:51:51 +0000 | [diff] [blame] | 8 | id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 9 | } |
| 10 | @property(strong) id x; |
| 11 | @property(strong) id y; |
| 12 | @property(strong) id z; |
| 13 | @end |
| 14 | |
| 15 | @interface Bar { |
| 16 | @public |
| 17 | id __unsafe_unretained x; |
| 18 | id __weak y; |
Fariborz Jahanian | 61740f6 | 2012-09-24 22:51:51 +0000 | [diff] [blame] | 19 | id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 20 | } |
| 21 | @property(retain) id x; |
| 22 | @property(retain) id y; |
| 23 | @property(retain) id z; |
| 24 | @end |
| 25 | |
| 26 | @interface Bas { |
| 27 | @public |
| 28 | id __unsafe_unretained x; |
| 29 | id __weak y; |
Fariborz Jahanian | 61740f6 | 2012-09-24 22:51:51 +0000 | [diff] [blame] | 30 | id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 31 | } |
| 32 | @property(copy) id x; |
| 33 | @property(copy) id y; |
| 34 | @property(copy) id z; |
| 35 | @end |
| 36 | |
| 37 | // Errors should start about here :-) |
| 38 | |
| 39 | @interface Bat |
| 40 | @property(strong) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} |
John McCall | b61e14e | 2015-10-27 04:54:50 +0000 | [diff] [blame] | 41 | @property(strong) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 42 | @property(strong) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} |
| 43 | @end |
| 44 | |
| 45 | @interface Bau |
| 46 | @property(retain) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} |
John McCall | b61e14e | 2015-10-27 04:54:50 +0000 | [diff] [blame] | 47 | @property(retain) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 48 | @property(retain) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} |
| 49 | @end |
| 50 | |
| 51 | @interface Bav |
| 52 | @property(copy) __unsafe_unretained id x; // expected-error {{strong property 'x' may not also be declared __unsafe_unretained}} |
John McCall | b61e14e | 2015-10-27 04:54:50 +0000 | [diff] [blame] | 53 | @property(copy) __weak id y; // expected-error {{strong property 'y' may not also be declared __weak}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 54 | @property(copy) __autoreleasing id z; // expected-error {{strong property 'z' may not also be declared __autoreleasing}} |
| 55 | @end |
| 56 | |
| 57 | @interface Bingo |
| 58 | @property(assign) __unsafe_unretained id x; |
John McCall | b61e14e | 2015-10-27 04:54:50 +0000 | [diff] [blame] | 59 | @property(assign) __weak id y; // expected-error {{unsafe_unretained property 'y' may not also be declared __weak}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 60 | @property(assign) __autoreleasing id z; // expected-error {{unsafe_unretained property 'z' may not also be declared __autoreleasing}} |
| 61 | @end |
| 62 | |
| 63 | @interface Batman |
| 64 | @property(unsafe_unretained) __unsafe_unretained id x; |
John McCall | b61e14e | 2015-10-27 04:54:50 +0000 | [diff] [blame] | 65 | @property(unsafe_unretained) __weak id y; // expected-error {{unsafe_unretained property 'y' may not also be declared __weak}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 66 | @property(unsafe_unretained) __autoreleasing id z; // expected-error {{unsafe_unretained property 'z' may not also be declared __autoreleasing}} |
| 67 | @end |
Fariborz Jahanian | 9059124 | 2011-10-08 17:45:33 +0000 | [diff] [blame] | 68 | |
| 69 | // rdar://9396329 |
| 70 | @interface Super |
| 71 | @property (readonly, retain) id foo; |
| 72 | @property (readonly, weak) id fee; |
| 73 | @property (readonly, strong) id frr; |
| 74 | @end |
| 75 | |
| 76 | @interface Bugg : Super |
| 77 | @property (readwrite) id foo; |
| 78 | @property (readwrite) id fee; |
| 79 | @property (readwrite) id frr; |
| 80 | @end |
| 81 | |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 82 | // rdar://20152386 |
Douglas Gregor | 2a20bd1 | 2015-06-19 18:25:57 +0000 | [diff] [blame] | 83 | // rdar://20383235 |
| 84 | |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 85 | @interface NSObject @end |
| 86 | |
Douglas Gregor | 2a20bd1 | 2015-06-19 18:25:57 +0000 | [diff] [blame] | 87 | #pragma clang assume_nonnull begin |
| 88 | @interface I: NSObject |
| 89 | @property(nonatomic, weak) id delegate; // Do not warn, nullable is inferred. |
| 90 | @property(nonatomic, weak, readonly) id ROdelegate; // Do not warn, nullable is inferred. |
| 91 | @property(nonatomic, weak, nonnull) id NonNulldelete; // expected-error {{property attributes 'nonnull' and 'weak' are mutually exclusive}} |
| 92 | @property(nonatomic, weak, nullable) id Nullabledelete; // do not warn |
| 93 | |
| 94 | // strong cases. |
| 95 | @property(nonatomic, strong) id stdelegate; // Do not warn |
| 96 | @property(nonatomic, readonly) id stROdelegate; // Do not warn |
| 97 | @property(nonatomic, strong, nonnull) id stNonNulldelete; // Do not warn |
| 98 | @property(nonatomic, nullable) id stNullabledelete; // do not warn |
| 99 | @end |
| 100 | #pragma clang assume_nonnull end |
| 101 | |
| 102 | @interface J: NSObject |
| 103 | @property(nonatomic, weak) id ddd; // Do not warn, nullable is inferred. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 104 | @property(nonatomic, weak, nonnull) id delegate; // expected-error {{property attributes 'nonnull' and 'weak' are mutually exclusive}} |
Douglas Gregor | 2a20bd1 | 2015-06-19 18:25:57 +0000 | [diff] [blame] | 105 | @property(nonatomic, weak, nonnull, readonly) id ROdelegate; // expected-error {{property attributes 'nonnull' and 'weak' are mutually exclusive}} |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 106 | @end |
| 107 | |