1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s 2f4a2713aSLionel Sambuc// rdar://9693477 3f4a2713aSLionel Sambuc 4f4a2713aSLionel Sambuc__attribute__((objc_arc_weak_reference_unavailable)) 5f4a2713aSLionel Sambuc@interface NSOptOut1072 // expected-note {{class is declared here}} 6f4a2713aSLionel Sambuc@end 7f4a2713aSLionel Sambuc 8f4a2713aSLionel Sambuc@interface sub : NSOptOut1072 @end // expected-note 2 {{class is declared here}} 9f4a2713aSLionel Sambuc 10f4a2713aSLionel Sambucint main() { 11f4a2713aSLionel Sambuc __weak sub *w2; // expected-error {{class is incompatible with __weak references}} 12f4a2713aSLionel Sambuc 13f4a2713aSLionel Sambuc __weak NSOptOut1072 *ns1; // expected-error {{class is incompatible with __weak references}} 14f4a2713aSLionel Sambuc 15f4a2713aSLionel Sambuc id obj; 16f4a2713aSLionel Sambuc 17f4a2713aSLionel Sambuc ns1 = (__weak sub *)obj; // expected-error {{assignment of a weak-unavailable object to a __weak object}} \ 18f4a2713aSLionel Sambuc // expected-error {{class is incompatible with __weak references}} \ 19f4a2713aSLionel Sambuc // expected-error {{explicit ownership qualifier on cast result has no effect}} 20f4a2713aSLionel Sambuc} 21f4a2713aSLionel Sambuc 22f4a2713aSLionel Sambuc// rdar://9732636 23f4a2713aSLionel Sambuc__attribute__((objc_arc_weak_reference_unavailable)) 24f4a2713aSLionel Sambuc@interface NOWEAK 25f4a2713aSLionel Sambuc+ (id) new; 26f4a2713aSLionel Sambuc@end 27f4a2713aSLionel Sambuc 28f4a2713aSLionel SambucNOWEAK * Test1() { 29f4a2713aSLionel Sambuc NOWEAK * strong1 = [NOWEAK new]; 30f4a2713aSLionel Sambuc __weak id weak1; 31f4a2713aSLionel Sambuc weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} 32f4a2713aSLionel Sambuc 33f4a2713aSLionel Sambuc __weak id weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} 34f4a2713aSLionel Sambuc return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}} \ 35f4a2713aSLionel Sambuc // expected-error {{explicit ownership qualifier on cast result has no effect}} 36f4a2713aSLionel Sambuc} 37f4a2713aSLionel Sambuc 38f4a2713aSLionel Sambuc@protocol P @end 39f4a2713aSLionel Sambuc@protocol P1 @end 40f4a2713aSLionel Sambuc 41f4a2713aSLionel SambucNOWEAK<P, P1> * Test2() { 42f4a2713aSLionel Sambuc NOWEAK<P, P1> * strong1 = 0; 43f4a2713aSLionel Sambuc __weak id<P> weak1; 44f4a2713aSLionel Sambuc weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} 45f4a2713aSLionel Sambuc 46f4a2713aSLionel Sambuc __weak id<P> weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}} 47f4a2713aSLionel Sambuc return (__weak id<P>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P>'}} \ 48f4a2713aSLionel Sambuc // expected-error {{explicit ownership qualifier on cast result has no effect}} 49f4a2713aSLionel Sambuc} 50f4a2713aSLionel Sambuc 51f4a2713aSLionel Sambuc// rdar://10535245 52f4a2713aSLionel Sambuc__attribute__((objc_arc_weak_reference_unavailable)) 53f4a2713aSLionel Sambuc@interface NSFont 54f4a2713aSLionel Sambuc@end 55f4a2713aSLionel Sambuc 56f4a2713aSLionel Sambuc@interface I 57f4a2713aSLionel Sambuc{ 58f4a2713aSLionel Sambuc} 59f4a2713aSLionel Sambuc@property (weak) NSFont *font; // expected-error {{synthesizing __weak instance variable of type 'NSFont *', which does not support weak references}} 60f4a2713aSLionel Sambuc@end 61f4a2713aSLionel Sambuc 62f4a2713aSLionel Sambuc@implementation I // expected-note {{when implemented by class I}} 63f4a2713aSLionel Sambuc@synthesize font = _font; 64f4a2713aSLionel Sambuc@end 65f4a2713aSLionel Sambuc 66f4a2713aSLionel Sambuc// rdar://13676793 67f4a2713aSLionel Sambuc@protocol MyProtocol 68f4a2713aSLionel Sambuc@property (weak) NSFont *font; // expected-error {{synthesizing __weak instance variable of type 'NSFont *', which does not support weak references}} 69f4a2713aSLionel Sambuc@end 70f4a2713aSLionel Sambuc 71f4a2713aSLionel Sambuc@interface I1 <MyProtocol> 72f4a2713aSLionel Sambuc@end 73f4a2713aSLionel Sambuc 74f4a2713aSLionel Sambuc@implementation I1 // expected-note {{when implemented by class I1}} 75f4a2713aSLionel Sambuc@synthesize font = _font; 76f4a2713aSLionel Sambuc@end 77f4a2713aSLionel Sambuc 78f4a2713aSLionel Sambuc@interface Super 79f4a2713aSLionel Sambuc@property (weak) NSFont *font; // expected-error {{synthesizing __weak instance variable of type 'NSFont *', which does not support weak references}} 80f4a2713aSLionel Sambuc@end 81f4a2713aSLionel Sambuc 82f4a2713aSLionel Sambuc 83f4a2713aSLionel Sambuc@interface I2 : Super 84f4a2713aSLionel Sambuc@end 85f4a2713aSLionel Sambuc 86f4a2713aSLionel Sambuc@implementation I2 // expected-note {{when implemented by class I2}} 87f4a2713aSLionel Sambuc@synthesize font = _font; 88f4a2713aSLionel Sambuc@end 89f4a2713aSLionel Sambuc 90f4a2713aSLionel Sambuc__attribute__((objc_arc_weak_reference_unavailable(1))) // expected-error {{'objc_arc_weak_reference_unavailable' attribute takes no arguments}} 91f4a2713aSLionel Sambuc@interface I3 92f4a2713aSLionel Sambuc@end 93*0a6a1f1dSLionel Sambuc 94*0a6a1f1dSLionel Sambucint I4 __attribute__((objc_arc_weak_reference_unavailable)); // expected-error {{'objc_arc_weak_reference_unavailable' attribute only applies to Objective-C interfaces}} 95