Patrick Beard | acfbe9e | 2012-04-06 18:12:22 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -verify -Wno-objc-root-class %s |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2 | |
| 3 | // rdar://8843524 |
| 4 | |
| 5 | struct A { |
Douglas Gregor | 0ad84b4 | 2013-01-28 20:13:44 +0000 | [diff] [blame] | 6 | id x; // expected-error {{ARC forbids Objective-C objects in struct}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 7 | }; |
| 8 | |
| 9 | union u { |
Douglas Gregor | 0ad84b4 | 2013-01-28 20:13:44 +0000 | [diff] [blame] | 10 | id u; // expected-error {{ARC forbids Objective-C objects in union}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 11 | }; |
| 12 | |
| 13 | @interface I { |
| 14 | struct A a; |
| 15 | struct B { |
Douglas Gregor | 0ad84b4 | 2013-01-28 20:13:44 +0000 | [diff] [blame] | 16 | id y[10][20]; // expected-error {{ARC forbids Objective-C objects in struct}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 17 | id z; |
| 18 | } b; |
| 19 | |
| 20 | union u c; |
| 21 | }; |
| 22 | @end |
| 23 | |
Fariborz Jahanian | b989e6e | 2011-12-12 23:17:04 +0000 | [diff] [blame] | 24 | // rdar://10260525 |
| 25 | struct r10260525 { |
Douglas Gregor | 0ad84b4 | 2013-01-28 20:13:44 +0000 | [diff] [blame] | 26 | id (^block) (); // expected-error {{ARC forbids blocks in struct}} |
Fariborz Jahanian | b989e6e | 2011-12-12 23:17:04 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 29 | struct S { |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 30 | id __attribute__((objc_ownership(none))) i; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 31 | void * vp; |
| 32 | int i1; |
| 33 | }; |
| 34 | |
| 35 | // rdar://9046528 |
| 36 | |
| 37 | @class NSError; |
| 38 | |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 39 | __autoreleasing id X; // expected-error {{global variables cannot have __autoreleasing ownership}} |
| 40 | __autoreleasing NSError *E; // expected-error {{global variables cannot have __autoreleasing ownership}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 41 | |
| 42 | |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 43 | extern id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 44 | |
| 45 | void func() |
| 46 | { |
| 47 | id X; |
Argyrios Kyrtzidis | cff00d9 | 2011-06-24 00:08:59 +0000 | [diff] [blame] | 48 | static id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}} |
| 49 | extern id __autoreleasing E; // expected-error {{global variables cannot have __autoreleasing ownership}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 50 | |
| 51 | } |
| 52 | |
| 53 | // rdar://9157348 |
Fariborz Jahanian | 65b1377 | 2014-01-10 00:53:48 +0000 | [diff] [blame] | 54 | // rdar://15757510 |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 55 | |
| 56 | @interface J |
Jordan Rose | a34d04d | 2015-01-16 23:04:31 +0000 | [diff] [blame^] | 57 | @property (retain) id newFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-newFoo' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} |
| 58 | @property (strong) id copyBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-copyBar' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} |
| 59 | @property (copy) id allocBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-allocBaz' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 60 | @property (copy, nonatomic) id new; |
Jordan Rose | a34d04d | 2015-01-16 23:04:31 +0000 | [diff] [blame^] | 61 | @property (retain) id newDFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-newDFoo' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} |
| 62 | @property (strong) id copyDBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-copyDBar' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} |
| 63 | @property (copy) id allocDBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-allocDBaz' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 64 | @end |
| 65 | |
| 66 | @implementation J |
Fariborz Jahanian | 65b1377 | 2014-01-10 00:53:48 +0000 | [diff] [blame] | 67 | @synthesize newFoo; |
| 68 | @synthesize copyBar; |
| 69 | @synthesize allocBaz; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 70 | @synthesize new; |
| 71 | - new {return 0; }; |
Fariborz Jahanian | 65b1377 | 2014-01-10 00:53:48 +0000 | [diff] [blame] | 72 | |
| 73 | @dynamic newDFoo; |
| 74 | @dynamic copyDBar; |
| 75 | @dynamic allocDBaz; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 76 | @end |
| 77 | |
Fariborz Jahanian | ac8dbf0 | 2011-09-27 22:35:36 +0000 | [diff] [blame] | 78 | |
Jordan Rose | a34d04d | 2015-01-16 23:04:31 +0000 | [diff] [blame^] | 79 | @interface MethodFamilyDiags |
| 80 | @property (retain) id newFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} |
| 81 | - (id)newFoo; // expected-note {{explicitly declare getter '-newFoo' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} |
| 82 | |
| 83 | #define OBJC_METHOD_FAMILY_NONE __attribute__((objc_method_family(none))) |
| 84 | - (id)newBar; // expected-note {{explicitly declare getter '-newBar' with 'OBJC_METHOD_FAMILY_NONE' to return an 'unowned' object}} |
| 85 | @property (retain) id newBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} |
| 86 | |
| 87 | @property (retain) id newBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note {{explicitly declare getter '-newBaz' with 'OBJC_METHOD_FAMILY_NONE' to return an 'unowned' object}} |
| 88 | #undef OBJC_METHOD_FAMILY_NONE |
| 89 | |
| 90 | @property (retain, readonly) id newGarply; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note {{explicitly declare getter '-newGarply' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} |
| 91 | @end |
| 92 | |
| 93 | @interface MethodFamilyDiags (Redeclarations) |
| 94 | - (id)newGarply; // no note here |
| 95 | @end |
| 96 | |
| 97 | @implementation MethodFamilyDiags |
| 98 | @synthesize newGarply; |
| 99 | @end |
| 100 | |
| 101 | |
Fariborz Jahanian | ac8dbf0 | 2011-09-27 22:35:36 +0000 | [diff] [blame] | 102 | // rdar://10187884 |
| 103 | @interface Super |
| 104 | - (void)bar:(id)b; // expected-note {{parameter declared here}} |
| 105 | - (void)bar1:(id) __attribute((ns_consumed)) b; |
| 106 | - (void)ok:(id) __attribute((ns_consumed)) b; |
| 107 | - (id)ns_non; // expected-note {{method declared here}} |
| 108 | - (id)not_ret:(id) b __attribute((ns_returns_not_retained)); // expected-note {{method declared here}} |
| 109 | - (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained)); |
| 110 | @end |
| 111 | |
| 112 | @interface Sub : Super |
| 113 | - (void)bar:(id) __attribute((ns_consumed)) b; // expected-error {{overriding method has mismatched ns_consumed attribute on its parameter}} |
| 114 | - (void)bar1:(id)b; |
| 115 | - (void)ok:(id) __attribute((ns_consumed)) b; |
| 116 | - (id)ns_non __attribute((ns_returns_not_retained)); // expected-error {{overriding method has mismatched ns_returns_not_retained attributes}} |
| 117 | - (id)not_ret:(id) b __attribute((ns_returns_retained)); // expected-error {{overriding method has mismatched ns_returns_retained attributes}} |
| 118 | - (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained)); |
Fariborz Jahanian | 272b7dc | 2012-08-28 22:26:21 +0000 | [diff] [blame] | 119 | // rdar://12173491 |
| 120 | @property (copy, nonatomic) __attribute__((ns_returns_retained)) id (^fblock)(void); |
Fariborz Jahanian | ac8dbf0 | 2011-09-27 22:35:36 +0000 | [diff] [blame] | 121 | @end |
John McCall | 18a962b | 2012-01-26 20:04:03 +0000 | [diff] [blame] | 122 | |
| 123 | // Test that we give a good diagnostic here that mentions the missing |
| 124 | // ownership qualifier. We don't want this to get suppressed because |
| 125 | // of an invalid conversion. |
| 126 | void test7(void) { |
| 127 | id x; |
| 128 | id *px = &x; // expected-error {{pointer to non-const type 'id' with no explicit ownership}} |
| 129 | |
| 130 | I *y; |
| 131 | J **py = &y; // expected-error {{pointer to non-const type 'J *' with no explicit ownership}} expected-warning {{incompatible pointer types initializing}} |
| 132 | } |
Aaron Ballman | 5e13985 | 2013-09-01 19:11:23 +0000 | [diff] [blame] | 133 | |
| 134 | void func(void) __attribute__((objc_ownership(none))); // expected-warning {{'objc_ownership' only applies to Objective-C object or block pointer types; type here is 'void (void)'}} |
| 135 | struct __attribute__((objc_ownership(none))) S2 {}; // expected-error {{'objc_ownership' attribute only applies to variables}} |
| 136 | @interface I2 |
| 137 | @property __attribute__((objc_ownership(frob))) id i; // expected-warning {{'objc_ownership' attribute argument not supported: 'frob'}} |
| 138 | @end |
Fariborz Jahanian | 7196487 | 2013-10-26 00:35:39 +0000 | [diff] [blame] | 139 | |
| 140 | // rdar://15304886 |
| 141 | @interface NSObject @end |
| 142 | |
| 143 | @interface ControllerClass : NSObject @end |
| 144 | |
| 145 | @interface SomeClassOwnedByController |
| 146 | @property (readonly) ControllerClass *controller; // expected-note {{property declared here}} |
Fariborz Jahanian | 3b65982 | 2013-11-19 19:26:30 +0000 | [diff] [blame] | 147 | |
| 148 | // rdar://15465916 |
| 149 | @property (readonly, weak) ControllerClass *weak_controller; |
Fariborz Jahanian | 7196487 | 2013-10-26 00:35:39 +0000 | [diff] [blame] | 150 | @end |
| 151 | |
| 152 | @interface SomeClassOwnedByController () |
| 153 | @property (readwrite, weak) ControllerClass *controller; // expected-warning {{primary property declaration is implicitly strong while redeclaration in class extension is weak}} |
Fariborz Jahanian | 3b65982 | 2013-11-19 19:26:30 +0000 | [diff] [blame] | 154 | |
| 155 | @property (readwrite, weak) ControllerClass *weak_controller; |
Fariborz Jahanian | 7196487 | 2013-10-26 00:35:39 +0000 | [diff] [blame] | 156 | @end |