153 lines · plain
1// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s2 3typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 3 {{declared here}}4 5typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 1 {{declared here}}6 7typedef struct __attribute__((objc_bridge(12))) __CFMyColor *CFMyColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}8 9typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{'objc_bridge' attribute takes one argument}}10 11typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}12 13typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}14 15typedef struct __attribute__((objc_bridge(NSLocale, NSError))) __CFLocale *CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}}16 17typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}18 19typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef; // expected-note {{declared here}}20 21typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}22 23typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}24 25typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}26 27typedef union __attribute__((objc_bridge(NSUColor))) __CFUPrimeColor XXX;28typedef XXX *CFUColor2Ref;29 30typedef const void *ConstVoidRef __attribute__((objc_bridge(id)));31typedef void *VoidRef __attribute__((objc_bridge(id)));32typedef struct Opaque *OpaqueRef __attribute__((objc_bridge(id))); // expected-error {{'objc_bridge(id)' is only allowed on structs and typedefs of void pointers}}33 34#if !__has_feature(objc_bridge_id_on_typedefs)35#error objc_bridge(id) on typedefs feature not found!36#endif37 38@interface I39{40 __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to structs, unions, classes, and typedefs}};41}42@end43 44@protocol NSTesting @end45@class NSString;46 47typedef struct __attribute__((objc_bridge(NSTesting))) __CFError *CFTestingRef; // expected-note {{declared here}}48 49id Test1(CFTestingRef cf) {50 return (NSString *)cf; // expected-error {{CF object of type 'CFTestingRef' (aka 'struct __CFError *') is bridged to 'NSTesting', which is not an Objective-C class}}51}52 53typedef CFErrorRef CFErrorRef1;54 55typedef CFErrorRef1 CFErrorRef2; // expected-note {{declared here}}56 57@protocol P1 @end58@protocol P2 @end59@protocol P3 @end60@protocol P4 @end61@protocol P5 @end62 63@interface NSError<P1, P2, P3> @end // expected-note 3 {{declared here}}64 65@interface MyError : NSError // expected-note 1 {{declared here}}66@end67 68@interface NSUColor @end69 70@class NSString;71 72void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {73 (void)(NSString *)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'NSString'}}74 (void)(NSError *)cf; // okay75 (void)(MyError*)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'MyError'}} 76 (void)(NSUColor *)cf2; // okay77 (void)(CFErrorRef)ns; // okay78 (void)(CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}79 (void)(Class)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'Class'}}80 (void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef'}}81}82 83 84void Test3(CFErrorRef cf, NSError *ns) {85 (void)(id)cf; // okay86 (void)(id<P1, P2>)cf; // okay87 (void)(id<P1, P2, P4>)cf; // expected-warning {{'CFErrorRef' (aka 'struct __CFErrorRef *') bridges to NSError, not 'id<P1,P2,P4>'}}88}89 90void Test4(CFMyErrorRef cf) {91 (void)(id)cf; // okay92 (void)(id<P1, P2>)cf; // ok93 (void)(id<P1, P2, P3>)cf; // ok94 (void)(id<P2, P3>)cf; // ok95 (void)(id<P1, P2, P4>)cf; // expected-warning {{'CFMyErrorRef' (aka 'struct __CFMyErrorRef *') bridges to MyError, not 'id<P1,P2,P4>'}}96}97 98void Test5(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) {99 (void)(CFErrorRef)ID; // ok100 (void)(CFErrorRef)P123; // ok101 (void)(CFErrorRef)P1234; // ok102 (void)(CFErrorRef)P12; // ok 103 (void)(CFErrorRef)P23; // ok104}105 106void Test6(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) {107 108 (void)(CFMyErrorRef)ID; // ok109 (void)(CFMyErrorRef)P123; // ok110 (void)(CFMyErrorRef)P1234; // ok111 (void)(CFMyErrorRef)P12; // ok112 (void)(CFMyErrorRef)P23; // ok113}114 115typedef struct __attribute__ ((objc_bridge(MyPersonalError))) __CFMyPersonalErrorRef * CFMyPersonalErrorRef; // expected-note 1 {{declared here}}116 117@interface MyPersonalError : NSError <P4> // expected-note 1 {{declared here}}118@end119 120void Test7(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) {121 (void)(CFMyPersonalErrorRef)ID; // ok122 (void)(CFMyPersonalErrorRef)P123; // ok123 (void)(CFMyPersonalErrorRef)P1234; // ok124 (void)(CFMyPersonalErrorRef)P12; // ok125 (void)(CFMyPersonalErrorRef)P23; // ok126}127 128void Test8(CFMyPersonalErrorRef cf) {129 (void)(id)cf; // ok130 (void)(id<P1>)cf; // ok131 (void)(id<P1, P2>)cf; // ok132 (void)(id<P1, P2, P3>)cf; // ok133 (void)(id<P1, P2, P3, P4>)cf; // ok134 (void)(id<P1, P2, P3, P4, P5>)cf; // expected-warning {{'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *') bridges to MyPersonalError, not 'id<P1,P2,P3,P4,P5>'}}135}136 137CFDictionaryRef bar(void) __attribute__((cf_returns_not_retained));138@class NSNumber;139 140void Test9(void) {141 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}}142}143 144@interface NSObject @end145 146@interface NSFont : NSObject @end147 148typedef struct __attribute__ ((objc_bridge(NSFont))) __CFFontRef * CFFontRef;149 150void Test10(CFFontRef cf) {151 (void)(__bridge NSObject *)cf;152}153