1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -verify -Wno-objc-root-class %s 2f4a2713aSLionel Sambuc 3f4a2713aSLionel Sambuc// rdar://8843524 4f4a2713aSLionel Sambuc 5f4a2713aSLionel Sambucstruct A { 6f4a2713aSLionel Sambuc id x; // expected-error {{ARC forbids Objective-C objects in struct}} 7f4a2713aSLionel Sambuc}; 8f4a2713aSLionel Sambuc 9f4a2713aSLionel Sambucunion u { 10f4a2713aSLionel Sambuc id u; // expected-error {{ARC forbids Objective-C objects in union}} 11f4a2713aSLionel Sambuc}; 12f4a2713aSLionel Sambuc 13f4a2713aSLionel Sambuc@interface I { 14f4a2713aSLionel Sambuc struct A a; 15f4a2713aSLionel Sambuc struct B { 16f4a2713aSLionel Sambuc id y[10][20]; // expected-error {{ARC forbids Objective-C objects in struct}} 17f4a2713aSLionel Sambuc id z; 18f4a2713aSLionel Sambuc } b; 19f4a2713aSLionel Sambuc 20f4a2713aSLionel Sambuc union u c; 21f4a2713aSLionel Sambuc}; 22f4a2713aSLionel Sambuc@end 23f4a2713aSLionel Sambuc 24f4a2713aSLionel Sambuc// rdar://10260525 25f4a2713aSLionel Sambucstruct r10260525 { 26f4a2713aSLionel Sambuc id (^block) (); // expected-error {{ARC forbids blocks in struct}} 27f4a2713aSLionel Sambuc}; 28f4a2713aSLionel Sambuc 29f4a2713aSLionel Sambucstruct S { 30f4a2713aSLionel Sambuc id __attribute__((objc_ownership(none))) i; 31f4a2713aSLionel Sambuc void * vp; 32f4a2713aSLionel Sambuc int i1; 33f4a2713aSLionel Sambuc}; 34f4a2713aSLionel Sambuc 35f4a2713aSLionel Sambuc// rdar://9046528 36f4a2713aSLionel Sambuc 37f4a2713aSLionel Sambuc@class NSError; 38f4a2713aSLionel Sambuc 39f4a2713aSLionel Sambuc__autoreleasing id X; // expected-error {{global variables cannot have __autoreleasing ownership}} 40f4a2713aSLionel Sambuc__autoreleasing NSError *E; // expected-error {{global variables cannot have __autoreleasing ownership}} 41f4a2713aSLionel Sambuc 42f4a2713aSLionel Sambuc 43f4a2713aSLionel Sambucextern id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}} 44f4a2713aSLionel Sambuc 45f4a2713aSLionel Sambucvoid func() 46f4a2713aSLionel Sambuc{ 47f4a2713aSLionel Sambuc id X; 48f4a2713aSLionel Sambuc static id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}} 49f4a2713aSLionel Sambuc extern id __autoreleasing E; // expected-error {{global variables cannot have __autoreleasing ownership}} 50f4a2713aSLionel Sambuc 51f4a2713aSLionel Sambuc} 52f4a2713aSLionel Sambuc 53f4a2713aSLionel Sambuc// rdar://9157348 54*0a6a1f1dSLionel Sambuc// rdar://15757510 55f4a2713aSLionel Sambuc 56f4a2713aSLionel Sambuc@interface J 57*0a6a1f1dSLionel Sambuc@property (retain) id newFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} 58*0a6a1f1dSLionel Sambuc@property (strong) id copyBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} 59*0a6a1f1dSLionel Sambuc@property (copy) id allocBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} 60f4a2713aSLionel Sambuc@property (copy, nonatomic) id new; 61*0a6a1f1dSLionel Sambuc@property (retain) id newDFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} 62*0a6a1f1dSLionel Sambuc@property (strong) id copyDBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} 63*0a6a1f1dSLionel Sambuc@property (copy) id allocDBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} 64f4a2713aSLionel Sambuc@end 65f4a2713aSLionel Sambuc 66f4a2713aSLionel Sambuc@implementation J 67*0a6a1f1dSLionel Sambuc@synthesize newFoo; 68*0a6a1f1dSLionel Sambuc@synthesize copyBar; 69*0a6a1f1dSLionel Sambuc@synthesize allocBaz; 70f4a2713aSLionel Sambuc@synthesize new; 71f4a2713aSLionel Sambuc- new {return 0; }; 72*0a6a1f1dSLionel Sambuc 73*0a6a1f1dSLionel Sambuc@dynamic newDFoo; 74*0a6a1f1dSLionel Sambuc@dynamic copyDBar; 75*0a6a1f1dSLionel Sambuc@dynamic allocDBaz; 76f4a2713aSLionel Sambuc@end 77f4a2713aSLionel Sambuc 78f4a2713aSLionel Sambuc 79f4a2713aSLionel Sambuc// rdar://10187884 80f4a2713aSLionel Sambuc@interface Super 81f4a2713aSLionel Sambuc- (void)bar:(id)b; // expected-note {{parameter declared here}} 82f4a2713aSLionel Sambuc- (void)bar1:(id) __attribute((ns_consumed)) b; 83f4a2713aSLionel Sambuc- (void)ok:(id) __attribute((ns_consumed)) b; 84f4a2713aSLionel Sambuc- (id)ns_non; // expected-note {{method declared here}} 85f4a2713aSLionel Sambuc- (id)not_ret:(id) b __attribute((ns_returns_not_retained)); // expected-note {{method declared here}} 86f4a2713aSLionel Sambuc- (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained)); 87f4a2713aSLionel Sambuc@end 88f4a2713aSLionel Sambuc 89f4a2713aSLionel Sambuc@interface Sub : Super 90f4a2713aSLionel Sambuc- (void)bar:(id) __attribute((ns_consumed)) b; // expected-error {{overriding method has mismatched ns_consumed attribute on its parameter}} 91f4a2713aSLionel Sambuc- (void)bar1:(id)b; 92f4a2713aSLionel Sambuc- (void)ok:(id) __attribute((ns_consumed)) b; 93f4a2713aSLionel Sambuc- (id)ns_non __attribute((ns_returns_not_retained)); // expected-error {{overriding method has mismatched ns_returns_not_retained attributes}} 94f4a2713aSLionel Sambuc- (id)not_ret:(id) b __attribute((ns_returns_retained)); // expected-error {{overriding method has mismatched ns_returns_retained attributes}} 95f4a2713aSLionel Sambuc- (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained)); 96f4a2713aSLionel Sambuc// rdar://12173491 97f4a2713aSLionel Sambuc@property (copy, nonatomic) __attribute__((ns_returns_retained)) id (^fblock)(void); 98f4a2713aSLionel Sambuc@end 99f4a2713aSLionel Sambuc 100f4a2713aSLionel Sambuc// Test that we give a good diagnostic here that mentions the missing 101f4a2713aSLionel Sambuc// ownership qualifier. We don't want this to get suppressed because 102f4a2713aSLionel Sambuc// of an invalid conversion. 103f4a2713aSLionel Sambucvoid test7(void) { 104f4a2713aSLionel Sambuc id x; 105f4a2713aSLionel Sambuc id *px = &x; // expected-error {{pointer to non-const type 'id' with no explicit ownership}} 106f4a2713aSLionel Sambuc 107f4a2713aSLionel Sambuc I *y; 108f4a2713aSLionel Sambuc J **py = &y; // expected-error {{pointer to non-const type 'J *' with no explicit ownership}} expected-warning {{incompatible pointer types initializing}} 109f4a2713aSLionel Sambuc} 110f4a2713aSLionel Sambuc 111f4a2713aSLionel Sambucvoid 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)'}} 112f4a2713aSLionel Sambucstruct __attribute__((objc_ownership(none))) S2 {}; // expected-error {{'objc_ownership' attribute only applies to variables}} 113f4a2713aSLionel Sambuc@interface I2 114f4a2713aSLionel Sambuc @property __attribute__((objc_ownership(frob))) id i; // expected-warning {{'objc_ownership' attribute argument not supported: 'frob'}} 115f4a2713aSLionel Sambuc@end 116f4a2713aSLionel Sambuc 117f4a2713aSLionel Sambuc// rdar://15304886 118f4a2713aSLionel Sambuc@interface NSObject @end 119f4a2713aSLionel Sambuc 120f4a2713aSLionel Sambuc@interface ControllerClass : NSObject @end 121f4a2713aSLionel Sambuc 122f4a2713aSLionel Sambuc@interface SomeClassOwnedByController 123f4a2713aSLionel Sambuc@property (readonly) ControllerClass *controller; // expected-note {{property declared here}} 124f4a2713aSLionel Sambuc 125f4a2713aSLionel Sambuc// rdar://15465916 126f4a2713aSLionel Sambuc@property (readonly, weak) ControllerClass *weak_controller; 127f4a2713aSLionel Sambuc@end 128f4a2713aSLionel Sambuc 129f4a2713aSLionel Sambuc@interface SomeClassOwnedByController () 130f4a2713aSLionel Sambuc@property (readwrite, weak) ControllerClass *controller; // expected-warning {{primary property declaration is implicitly strong while redeclaration in class extension is weak}} 131f4a2713aSLionel Sambuc 132f4a2713aSLionel Sambuc@property (readwrite, weak) ControllerClass *weak_controller; 133f4a2713aSLionel Sambuc@end 134