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