blob: 7fcf576f7000eb3ab47d94a5b57bf86e5c30fcc1 [file] [log] [blame]
Patrick Beardacfbe9e2012-04-06 18:12:22 +00001// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -verify -Wno-objc-root-class %s
John McCall31168b02011-06-15 23:02:42 +00002
3// rdar://8843524
4
5struct A {
Douglas Gregor0ad84b42013-01-28 20:13:44 +00006 id x; // expected-error {{ARC forbids Objective-C objects in struct}}
John McCall31168b02011-06-15 23:02:42 +00007};
8
9union u {
Douglas Gregor0ad84b42013-01-28 20:13:44 +000010 id u; // expected-error {{ARC forbids Objective-C objects in union}}
John McCall31168b02011-06-15 23:02:42 +000011};
12
13@interface I {
14 struct A a;
15 struct B {
Douglas Gregor0ad84b42013-01-28 20:13:44 +000016 id y[10][20]; // expected-error {{ARC forbids Objective-C objects in struct}}
John McCall31168b02011-06-15 23:02:42 +000017 id z;
18 } b;
19
20 union u c;
21};
22@end
23
Fariborz Jahanianb989e6e2011-12-12 23:17:04 +000024// rdar://10260525
25struct r10260525 {
Douglas Gregor0ad84b42013-01-28 20:13:44 +000026 id (^block) (); // expected-error {{ARC forbids blocks in struct}}
Fariborz Jahanianb989e6e2011-12-12 23:17:04 +000027};
28
John McCall31168b02011-06-15 23:02:42 +000029struct S {
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +000030 id __attribute__((objc_ownership(none))) i;
John McCall31168b02011-06-15 23:02:42 +000031 void * vp;
32 int i1;
33};
34
35// rdar://9046528
36
37@class NSError;
38
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +000039__autoreleasing id X; // expected-error {{global variables cannot have __autoreleasing ownership}}
40__autoreleasing NSError *E; // expected-error {{global variables cannot have __autoreleasing ownership}}
John McCall31168b02011-06-15 23:02:42 +000041
42
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +000043extern id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}}
John McCall31168b02011-06-15 23:02:42 +000044
45void func()
46{
47 id X;
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +000048 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 McCall31168b02011-06-15 23:02:42 +000050
51}
52
53// rdar://9157348
Fariborz Jahanian65b13772014-01-10 00:53:48 +000054// rdar://15757510
John McCall31168b02011-06-15 23:02:42 +000055
56@interface J
Fariborz Jahanian65b13772014-01-10 00:53:48 +000057@property (retain) id newFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}}
58@property (strong) id copyBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}}
59@property (copy) id allocBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}}
John McCall31168b02011-06-15 23:02:42 +000060@property (copy, nonatomic) id new;
Fariborz Jahanian65b13772014-01-10 00:53:48 +000061@property (retain) id newDFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}}
62@property (strong) id copyDBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}}
63@property (copy) id allocDBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}}
John McCall31168b02011-06-15 23:02:42 +000064@end
65
66@implementation J
Fariborz Jahanian65b13772014-01-10 00:53:48 +000067@synthesize newFoo;
68@synthesize copyBar;
69@synthesize allocBaz;
John McCall31168b02011-06-15 23:02:42 +000070@synthesize new;
71- new {return 0; };
Fariborz Jahanian65b13772014-01-10 00:53:48 +000072
73@dynamic newDFoo;
74@dynamic copyDBar;
75@dynamic allocDBaz;
John McCall31168b02011-06-15 23:02:42 +000076@end
77
Fariborz Jahanianac8dbf02011-09-27 22:35:36 +000078
79// rdar://10187884
80@interface Super
81- (void)bar:(id)b; // expected-note {{parameter declared here}}
82- (void)bar1:(id) __attribute((ns_consumed)) b;
83- (void)ok:(id) __attribute((ns_consumed)) b;
84- (id)ns_non; // expected-note {{method declared here}}
85- (id)not_ret:(id) b __attribute((ns_returns_not_retained)); // expected-note {{method declared here}}
86- (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained));
87@end
88
89@interface Sub : Super
90- (void)bar:(id) __attribute((ns_consumed)) b; // expected-error {{overriding method has mismatched ns_consumed attribute on its parameter}}
91- (void)bar1:(id)b;
92- (void)ok:(id) __attribute((ns_consumed)) b;
93- (id)ns_non __attribute((ns_returns_not_retained)); // expected-error {{overriding method has mismatched ns_returns_not_retained attributes}}
94- (id)not_ret:(id) b __attribute((ns_returns_retained)); // expected-error {{overriding method has mismatched ns_returns_retained attributes}}
95- (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained));
Fariborz Jahanian272b7dc2012-08-28 22:26:21 +000096// rdar://12173491
97@property (copy, nonatomic) __attribute__((ns_returns_retained)) id (^fblock)(void);
Fariborz Jahanianac8dbf02011-09-27 22:35:36 +000098@end
John McCall18a962b2012-01-26 20:04:03 +000099
100// Test that we give a good diagnostic here that mentions the missing
101// ownership qualifier. We don't want this to get suppressed because
102// of an invalid conversion.
103void test7(void) {
104 id x;
105 id *px = &x; // expected-error {{pointer to non-const type 'id' with no explicit ownership}}
106
107 I *y;
108 J **py = &y; // expected-error {{pointer to non-const type 'J *' with no explicit ownership}} expected-warning {{incompatible pointer types initializing}}
109}
Aaron Ballman5e139852013-09-01 19:11:23 +0000110
111void 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)'}}
112struct __attribute__((objc_ownership(none))) S2 {}; // expected-error {{'objc_ownership' attribute only applies to variables}}
113@interface I2
114 @property __attribute__((objc_ownership(frob))) id i; // expected-warning {{'objc_ownership' attribute argument not supported: 'frob'}}
115@end
Fariborz Jahanian71964872013-10-26 00:35:39 +0000116
117// rdar://15304886
118@interface NSObject @end
119
120@interface ControllerClass : NSObject @end
121
122@interface SomeClassOwnedByController
123@property (readonly) ControllerClass *controller; // expected-note {{property declared here}}
Fariborz Jahanian3b659822013-11-19 19:26:30 +0000124
125// rdar://15465916
126@property (readonly, weak) ControllerClass *weak_controller;
Fariborz Jahanian71964872013-10-26 00:35:39 +0000127@end
128
129@interface SomeClassOwnedByController ()
130@property (readwrite, weak) ControllerClass *controller; // expected-warning {{primary property declaration is implicitly strong while redeclaration in class extension is weak}}
Fariborz Jahanian3b659822013-11-19 19:26:30 +0000131
132@property (readwrite, weak) ControllerClass *weak_controller;
Fariborz Jahanian71964872013-10-26 00:35:39 +0000133@end