| Fariborz Jahanian | a649c82 | 2013-11-15 22:18:17 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 2 | // rdar://15454846 |
| 3 | |
| Fariborz Jahanian | 92ab298 | 2013-11-20 00:32:12 +0000 | [diff] [blame] | 4 | typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 5 {{declared here}} |
| 5 | |
| 6 | typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 3 {{declared here}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 7 | |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 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}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 9 | |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 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}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 11 | |
| Fariborz Jahanian | f720f86 | 2013-11-19 17:42:25 +0000 | [diff] [blame] | 12 | typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 13 | |
| Fariborz Jahanian | f720f86 | 2013-11-19 17:42:25 +0000 | [diff] [blame] | 14 | typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{'objc_bridge' attribute only applies to struct or union}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 15 | |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 16 | typedef struct __attribute__((objc_bridge(NSLocale, NSError))) __CFLocale *CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 17 | |
| Fariborz Jahanian | f720f86 | 2013-11-19 17:42:25 +0000 | [diff] [blame] | 18 | typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 19 | |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 20 | typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef; |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 21 | |
| Fariborz Jahanian | f720f86 | 2013-11-19 17:42:25 +0000 | [diff] [blame] | 22 | typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); // expected-error {{'objc_bridge' attribute only applies to struct or union}}; |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 23 | |
| Fariborz Jahanian | f720f86 | 2013-11-19 17:42:25 +0000 | [diff] [blame] | 24 | typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}}; |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 25 | |
| Fariborz Jahanian | f720f86 | 2013-11-19 17:42:25 +0000 | [diff] [blame] | 26 | typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; // expected-error {{'objc_bridge' attribute only applies to struct or union}}; |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 27 | |
| 28 | typedef union __attribute__((objc_bridge(NSUColor))) __CFUPrimeColor XXX; |
| 29 | typedef XXX *CFUColor2Ref; |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 30 | |
| 31 | @interface I |
| 32 | { |
| Fariborz Jahanian | f720f86 | 2013-11-19 17:42:25 +0000 | [diff] [blame] | 33 | __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to struct or union}}; |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 34 | } |
| 35 | @end |
| Fariborz Jahanian | a649c82 | 2013-11-15 22:18:17 +0000 | [diff] [blame] | 36 | |
| 37 | @protocol NSTesting @end |
| 38 | @class NSString; |
| 39 | |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 40 | typedef struct __attribute__((objc_bridge(NSTesting))) __CFError *CFTestingRef; // expected-note {{declared here}} |
| Fariborz Jahanian | a649c82 | 2013-11-15 22:18:17 +0000 | [diff] [blame] | 41 | |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 42 | id Test1(CFTestingRef cf) { |
| Fariborz Jahanian | b823319 | 2013-11-15 23:14:45 +0000 | [diff] [blame] | 43 | return (NSString *)cf; // expected-error {{CF object of type 'CFTestingRef' (aka 'struct __CFError *') is bridged to 'NSTesting', which is not an Objective-C class}} |
| Fariborz Jahanian | a649c82 | 2013-11-15 22:18:17 +0000 | [diff] [blame] | 44 | } |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 45 | |
| 46 | typedef CFErrorRef CFErrorRef1; |
| 47 | |
| Fariborz Jahanian | 92ab298 | 2013-11-20 00:32:12 +0000 | [diff] [blame] | 48 | typedef CFErrorRef1 CFErrorRef2; // expected-note {{declared here}} |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 49 | |
| Fariborz Jahanian | 92ab298 | 2013-11-20 00:32:12 +0000 | [diff] [blame] | 50 | @protocol P1 @end |
| 51 | @protocol P2 @end |
| 52 | @protocol P3 @end |
| 53 | @protocol P4 @end |
| Fariborz Jahanian | 91fb0be | 2013-11-20 19:01:50 +0000 | [diff] [blame^] | 54 | @protocol P5 @end |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 55 | |
| Fariborz Jahanian | 92ab298 | 2013-11-20 00:32:12 +0000 | [diff] [blame] | 56 | @interface NSError<P1, P2, P3> @end // expected-note 5 {{declared here}} |
| 57 | |
| 58 | @interface MyError : NSError // expected-note 3 {{declared here}} |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 59 | @end |
| 60 | |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 61 | @interface NSUColor @end |
| 62 | |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 63 | @class NSString; |
| 64 | |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 65 | void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) { |
| Fariborz Jahanian | 509f31e | 2013-11-19 01:23:07 +0000 | [diff] [blame] | 66 | (void)(NSString *)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'NSString'}} |
| Fariborz Jahanian | f07183c | 2013-11-16 01:45:25 +0000 | [diff] [blame] | 67 | (void)(NSError *)cf; // okay |
| 68 | (void)(MyError*)cf; // okay, |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 69 | (void)(NSUColor *)cf2; // okay |
| Fariborz Jahanian | 8a0210e | 2013-11-16 19:16:32 +0000 | [diff] [blame] | 70 | (void)(CFErrorRef)ns; // okay |
| Fariborz Jahanian | 509f31e | 2013-11-19 01:23:07 +0000 | [diff] [blame] | 71 | (void)(CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}} |
| 72 | (void)(Class)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'Class'}} |
| Fariborz Jahanian | 2c31212 | 2013-11-16 23:22:37 +0000 | [diff] [blame] | 73 | (void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef'}} |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 74 | } |
| Fariborz Jahanian | 92ab298 | 2013-11-20 00:32:12 +0000 | [diff] [blame] | 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 'struct __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 'struct __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 'struct __CFErrorRef *')}} |
| 96 | (void)(CFErrorRef)P23; // expected-warning {{'id<P2,P3>' cannot bridge to 'CFErrorRef' (aka 'struct __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 'struct __CFMyErrorRef *')}} |
| 105 | (void)(CFMyErrorRef)P23; // expected-warning {{'id<P2,P3>' cannot bridge to 'CFMyErrorRef' (aka 'struct __CFMyErrorRef *')}} |
| 106 | } |
| Fariborz Jahanian | 91fb0be | 2013-11-20 19:01:50 +0000 | [diff] [blame^] | 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 'struct __CFMyPersonalErrorRef *')}} |
| 116 | (void)(CFMyPersonalErrorRef)P1234; // ok |
| 117 | (void)(CFMyPersonalErrorRef)P12; // expected-warning {{'id<P1,P2>' cannot bridge to 'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *')}} |
| 118 | (void)(CFMyPersonalErrorRef)P23; // expected-warning {{'id<P2,P3>' cannot bridge to 'CFMyPersonalErrorRef' (aka 'struct __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 'struct __CFMyPersonalErrorRef *') bridges to MyPersonalError, not 'id<P1,P2,P3,P4,P5>'}} |
| 128 | } |
| 129 | |