1*0a6a1f1dSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s 2f4a2713aSLionel Sambuc// rdar://15454846 3f4a2713aSLionel Sambuc 4*0a6a1f1dSLionel Sambuctypedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 3 {{declared here}} 5*0a6a1f1dSLionel Sambuc 6*0a6a1f1dSLionel Sambuctypedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 1 {{declared here}} 7f4a2713aSLionel Sambuc 8f4a2713aSLionel Sambuctypedef struct __attribute__((objc_bridge(12))) __CFMyColor *CFMyColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}} 9f4a2713aSLionel Sambuc 10*0a6a1f1dSLionel Sambuctypedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{'objc_bridge' attribute takes one argument}} 11f4a2713aSLionel Sambuc 12f4a2713aSLionel Sambuctypedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}} 13f4a2713aSLionel Sambuc 14f4a2713aSLionel Sambuctypedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{'objc_bridge' attribute only applies to struct or union}} 15f4a2713aSLionel Sambuc 16f4a2713aSLionel Sambuctypedef struct __attribute__((objc_bridge(NSLocale, NSError))) __CFLocale *CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}} 17f4a2713aSLionel Sambuc 18f4a2713aSLionel Sambuctypedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}} 19f4a2713aSLionel Sambuc 20*0a6a1f1dSLionel Sambuctypedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef; // expected-note {{declared here}} 21f4a2713aSLionel Sambuc 22f4a2713aSLionel Sambuctypedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); // expected-error {{'objc_bridge' attribute only applies to struct or union}}; 23f4a2713aSLionel Sambuc 24f4a2713aSLionel Sambuctypedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}}; 25f4a2713aSLionel Sambuc 26f4a2713aSLionel Sambuctypedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; // expected-error {{'objc_bridge' attribute only applies to struct or union}}; 27f4a2713aSLionel Sambuc 28f4a2713aSLionel Sambuctypedef union __attribute__((objc_bridge(NSUColor))) __CFUPrimeColor XXX; 29f4a2713aSLionel Sambuctypedef XXX *CFUColor2Ref; 30f4a2713aSLionel Sambuc 31f4a2713aSLionel Sambuc@interface I 32f4a2713aSLionel Sambuc{ 33f4a2713aSLionel Sambuc __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to struct or union}}; 34f4a2713aSLionel Sambuc} 35f4a2713aSLionel Sambuc@end 36f4a2713aSLionel Sambuc 37f4a2713aSLionel Sambuc@protocol NSTesting @end 38f4a2713aSLionel Sambuc@class NSString; 39f4a2713aSLionel Sambuc 40f4a2713aSLionel Sambuctypedef struct __attribute__((objc_bridge(NSTesting))) __CFError *CFTestingRef; // expected-note {{declared here}} 41f4a2713aSLionel Sambuc 42f4a2713aSLionel Sambucid Test1(CFTestingRef cf) { 43f4a2713aSLionel Sambuc return (NSString *)cf; // expected-error {{CF object of type 'CFTestingRef' (aka 'struct __CFError *') is bridged to 'NSTesting', which is not an Objective-C class}} 44f4a2713aSLionel Sambuc} 45f4a2713aSLionel Sambuc 46f4a2713aSLionel Sambuctypedef CFErrorRef CFErrorRef1; 47f4a2713aSLionel Sambuc 48*0a6a1f1dSLionel Sambuctypedef CFErrorRef1 CFErrorRef2; // expected-note {{declared here}} 49f4a2713aSLionel Sambuc 50*0a6a1f1dSLionel Sambuc@protocol P1 @end 51*0a6a1f1dSLionel Sambuc@protocol P2 @end 52*0a6a1f1dSLionel Sambuc@protocol P3 @end 53*0a6a1f1dSLionel Sambuc@protocol P4 @end 54*0a6a1f1dSLionel Sambuc@protocol P5 @end 55f4a2713aSLionel Sambuc 56*0a6a1f1dSLionel Sambuc@interface NSError<P1, P2, P3> @end // expected-note 3 {{declared here}} 57*0a6a1f1dSLionel Sambuc 58*0a6a1f1dSLionel Sambuc@interface MyError : NSError // expected-note 1 {{declared here}} 59f4a2713aSLionel Sambuc@end 60f4a2713aSLionel Sambuc 61f4a2713aSLionel Sambuc@interface NSUColor @end 62f4a2713aSLionel Sambuc 63f4a2713aSLionel Sambuc@class NSString; 64f4a2713aSLionel Sambuc 65f4a2713aSLionel Sambucvoid Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) { 66f4a2713aSLionel Sambuc (void)(NSString *)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'NSString'}} 67f4a2713aSLionel Sambuc (void)(NSError *)cf; // okay 68f4a2713aSLionel Sambuc (void)(MyError*)cf; // okay, 69f4a2713aSLionel Sambuc (void)(NSUColor *)cf2; // okay 70f4a2713aSLionel Sambuc (void)(CFErrorRef)ns; // okay 71f4a2713aSLionel Sambuc (void)(CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}} 72f4a2713aSLionel Sambuc (void)(Class)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'Class'}} 73f4a2713aSLionel Sambuc (void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef'}} 74f4a2713aSLionel Sambuc} 75*0a6a1f1dSLionel Sambuc 76*0a6a1f1dSLionel Sambuc 77*0a6a1f1dSLionel Sambucvoid Test3(CFErrorRef cf, NSError *ns) { 78*0a6a1f1dSLionel Sambuc (void)(id)cf; // okay 79*0a6a1f1dSLionel Sambuc (void)(id<P1, P2>)cf; // okay 80*0a6a1f1dSLionel Sambuc (void)(id<P1, P2, P4>)cf; // expected-warning {{'CFErrorRef' (aka 'struct __CFErrorRef *') bridges to NSError, not 'id<P1,P2,P4>'}} 81*0a6a1f1dSLionel Sambuc} 82*0a6a1f1dSLionel Sambuc 83*0a6a1f1dSLionel Sambucvoid Test4(CFMyErrorRef cf) { 84*0a6a1f1dSLionel Sambuc (void)(id)cf; // okay 85*0a6a1f1dSLionel Sambuc (void)(id<P1, P2>)cf; // ok 86*0a6a1f1dSLionel Sambuc (void)(id<P1, P2, P3>)cf; // ok 87*0a6a1f1dSLionel Sambuc (void)(id<P2, P3>)cf; // ok 88*0a6a1f1dSLionel Sambuc (void)(id<P1, P2, P4>)cf; // expected-warning {{'CFMyErrorRef' (aka 'struct __CFMyErrorRef *') bridges to MyError, not 'id<P1,P2,P4>'}} 89*0a6a1f1dSLionel Sambuc} 90*0a6a1f1dSLionel Sambuc 91*0a6a1f1dSLionel Sambucvoid Test5(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) { 92*0a6a1f1dSLionel Sambuc (void)(CFErrorRef)ID; // ok 93*0a6a1f1dSLionel Sambuc (void)(CFErrorRef)P123; // ok 94*0a6a1f1dSLionel Sambuc (void)(CFErrorRef)P1234; // ok 95*0a6a1f1dSLionel Sambuc (void)(CFErrorRef)P12; // ok 96*0a6a1f1dSLionel Sambuc (void)(CFErrorRef)P23; // ok 97*0a6a1f1dSLionel Sambuc} 98*0a6a1f1dSLionel Sambuc 99*0a6a1f1dSLionel Sambucvoid Test6(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) { 100*0a6a1f1dSLionel Sambuc 101*0a6a1f1dSLionel Sambuc (void)(CFMyErrorRef)ID; // ok 102*0a6a1f1dSLionel Sambuc (void)(CFMyErrorRef)P123; // ok 103*0a6a1f1dSLionel Sambuc (void)(CFMyErrorRef)P1234; // ok 104*0a6a1f1dSLionel Sambuc (void)(CFMyErrorRef)P12; // ok 105*0a6a1f1dSLionel Sambuc (void)(CFMyErrorRef)P23; // ok 106*0a6a1f1dSLionel Sambuc} 107*0a6a1f1dSLionel Sambuc 108*0a6a1f1dSLionel Sambuctypedef struct __attribute__ ((objc_bridge(MyPersonalError))) __CFMyPersonalErrorRef * CFMyPersonalErrorRef; // expected-note 1 {{declared here}} 109*0a6a1f1dSLionel Sambuc 110*0a6a1f1dSLionel Sambuc@interface MyPersonalError : NSError <P4> // expected-note 1 {{declared here}} 111*0a6a1f1dSLionel Sambuc@end 112*0a6a1f1dSLionel Sambuc 113*0a6a1f1dSLionel Sambucvoid Test7(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) { 114*0a6a1f1dSLionel Sambuc (void)(CFMyPersonalErrorRef)ID; // ok 115*0a6a1f1dSLionel Sambuc (void)(CFMyPersonalErrorRef)P123; // ok 116*0a6a1f1dSLionel Sambuc (void)(CFMyPersonalErrorRef)P1234; // ok 117*0a6a1f1dSLionel Sambuc (void)(CFMyPersonalErrorRef)P12; // ok 118*0a6a1f1dSLionel Sambuc (void)(CFMyPersonalErrorRef)P23; // ok 119*0a6a1f1dSLionel Sambuc} 120*0a6a1f1dSLionel Sambuc 121*0a6a1f1dSLionel Sambucvoid Test8(CFMyPersonalErrorRef cf) { 122*0a6a1f1dSLionel Sambuc (void)(id)cf; // ok 123*0a6a1f1dSLionel Sambuc (void)(id<P1>)cf; // ok 124*0a6a1f1dSLionel Sambuc (void)(id<P1, P2>)cf; // ok 125*0a6a1f1dSLionel Sambuc (void)(id<P1, P2, P3>)cf; // ok 126*0a6a1f1dSLionel Sambuc (void)(id<P1, P2, P3, P4>)cf; // ok 127*0a6a1f1dSLionel Sambuc (void)(id<P1, P2, P3, P4, P5>)cf; // expected-warning {{'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *') bridges to MyPersonalError, not 'id<P1,P2,P3,P4,P5>'}} 128*0a6a1f1dSLionel Sambuc} 129*0a6a1f1dSLionel Sambuc 130*0a6a1f1dSLionel SambucCFDictionaryRef bar() __attribute__((cf_returns_not_retained)); 131*0a6a1f1dSLionel Sambuc@class NSNumber; 132*0a6a1f1dSLionel Sambuc 133*0a6a1f1dSLionel Sambucvoid Test9() { 134*0a6a1f1dSLionel Sambuc NSNumber *w2 = (NSNumber*) bar(); // expected-error {{CF object of type 'CFDictionaryRef' (aka 'struct __CFDictionary *') is bridged to 'NSDictionary', which is not an Objective-C class}} 135*0a6a1f1dSLionel Sambuc} 136