| Fariborz Jahanian | 8c5b4be | 2013-11-21 00:39:36 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 2 | // rdar://15454846 |
| 3 | |
| Fariborz Jahanian | 48a01cb | 2014-04-04 23:53:45 +0000 | [diff] [blame] | 4 | typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 3 {{declared here}} |
| Fariborz Jahanian | 92ab298 | 2013-11-20 00:32:12 +0000 | [diff] [blame] | 5 | |
| Fariborz Jahanian | 48a01cb | 2014-04-04 23:53:45 +0000 | [diff] [blame] | 6 | typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 1 {{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 | 2651ac5 | 2013-11-22 00:02:22 +0000 | [diff] [blame] | 10 | typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{'objc_bridge' attribute takes one argument}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 11 | |
| John McCall | 2859258 | 2015-02-01 22:34:06 +0000 | [diff] [blame] | 12 | typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 13 | |
| John McCall | 2859258 | 2015-02-01 22:34:06 +0000 | [diff] [blame] | 14 | typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}} |
| 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 | |
| John McCall | 2859258 | 2015-02-01 22:34:06 +0000 | [diff] [blame] | 18 | typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 19 | |
| Fariborz Jahanian | f1a22f4 | 2014-04-29 16:12:56 +0000 | [diff] [blame] | 20 | typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef; // expected-note {{declared here}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 21 | |
| John McCall | 2859258 | 2015-02-01 22:34:06 +0000 | [diff] [blame] | 22 | typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}} |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 23 | |
| John McCall | 2859258 | 2015-02-01 22:34:06 +0000 | [diff] [blame] | 24 | typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}} |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 25 | |
| John McCall | 2859258 | 2015-02-01 22:34:06 +0000 | [diff] [blame] | 26 | typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}} |
| 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 | |
| John McCall | 2859258 | 2015-02-01 22:34:06 +0000 | [diff] [blame] | 31 | typedef const void *ConstVoidRef __attribute__((objc_bridge(id))); |
| 32 | typedef void *VoidRef __attribute__((objc_bridge(id))); |
| 33 | typedef struct Opaque *OpaqueRef __attribute__((objc_bridge(id))); // expected-error {{'objc_bridge(id)' is only allowed on structs and typedefs of void pointers}} |
| 34 | |
| 35 | #if !__has_feature(objc_bridge_id_on_typedefs) |
| 36 | #error objc_bridge(id) on typedefs feature not found! |
| 37 | #endif |
| 38 | |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 39 | @interface I |
| 40 | { |
| John McCall | 2859258 | 2015-02-01 22:34:06 +0000 | [diff] [blame] | 41 | __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to structs, unions, and typedefs}}; |
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 42 | } |
| 43 | @end |
| Fariborz Jahanian | a649c82 | 2013-11-15 22:18:17 +0000 | [diff] [blame] | 44 | |
| 45 | @protocol NSTesting @end |
| 46 | @class NSString; |
| 47 | |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 48 | typedef struct __attribute__((objc_bridge(NSTesting))) __CFError *CFTestingRef; // expected-note {{declared here}} |
| Fariborz Jahanian | a649c82 | 2013-11-15 22:18:17 +0000 | [diff] [blame] | 49 | |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 50 | id Test1(CFTestingRef cf) { |
| Fariborz Jahanian | b823319 | 2013-11-15 23:14:45 +0000 | [diff] [blame] | 51 | 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] | 52 | } |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 53 | |
| 54 | typedef CFErrorRef CFErrorRef1; |
| 55 | |
| Fariborz Jahanian | 8c5b4be | 2013-11-21 00:39:36 +0000 | [diff] [blame] | 56 | typedef CFErrorRef1 CFErrorRef2; // expected-note {{declared here}} |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 57 | |
| Fariborz Jahanian | 92ab298 | 2013-11-20 00:32:12 +0000 | [diff] [blame] | 58 | @protocol P1 @end |
| 59 | @protocol P2 @end |
| 60 | @protocol P3 @end |
| 61 | @protocol P4 @end |
| Fariborz Jahanian | 91fb0be | 2013-11-20 19:01:50 +0000 | [diff] [blame] | 62 | @protocol P5 @end |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 63 | |
| Fariborz Jahanian | 48a01cb | 2014-04-04 23:53:45 +0000 | [diff] [blame] | 64 | @interface NSError<P1, P2, P3> @end // expected-note 3 {{declared here}} |
| Fariborz Jahanian | 92ab298 | 2013-11-20 00:32:12 +0000 | [diff] [blame] | 65 | |
| Fariborz Jahanian | 48a01cb | 2014-04-04 23:53:45 +0000 | [diff] [blame] | 66 | @interface MyError : NSError // expected-note 1 {{declared here}} |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 67 | @end |
| 68 | |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 69 | @interface NSUColor @end |
| 70 | |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 71 | @class NSString; |
| 72 | |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 73 | void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) { |
| Fariborz Jahanian | 509f31e | 2013-11-19 01:23:07 +0000 | [diff] [blame] | 74 | (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] | 75 | (void)(NSError *)cf; // okay |
| Fariborz Jahanian | 27aa9b4 | 2015-04-10 22:07:47 +0000 | [diff] [blame] | 76 | (void)(MyError*)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'MyError'}} |
| Fariborz Jahanian | db3d855 | 2013-11-19 00:09:48 +0000 | [diff] [blame] | 77 | (void)(NSUColor *)cf2; // okay |
| Fariborz Jahanian | 8a0210e | 2013-11-16 19:16:32 +0000 | [diff] [blame] | 78 | (void)(CFErrorRef)ns; // okay |
| Fariborz Jahanian | 509f31e | 2013-11-19 01:23:07 +0000 | [diff] [blame] | 79 | (void)(CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}} |
| 80 | (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] | 81 | (void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef'}} |
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 82 | } |
| Fariborz Jahanian | 92ab298 | 2013-11-20 00:32:12 +0000 | [diff] [blame] | 83 | |
| 84 | |
| 85 | void Test3(CFErrorRef cf, NSError *ns) { |
| 86 | (void)(id)cf; // okay |
| 87 | (void)(id<P1, P2>)cf; // okay |
| 88 | (void)(id<P1, P2, P4>)cf; // expected-warning {{'CFErrorRef' (aka 'struct __CFErrorRef *') bridges to NSError, not 'id<P1,P2,P4>'}} |
| 89 | } |
| 90 | |
| 91 | void Test4(CFMyErrorRef cf) { |
| 92 | (void)(id)cf; // okay |
| 93 | (void)(id<P1, P2>)cf; // ok |
| 94 | (void)(id<P1, P2, P3>)cf; // ok |
| 95 | (void)(id<P2, P3>)cf; // ok |
| 96 | (void)(id<P1, P2, P4>)cf; // expected-warning {{'CFMyErrorRef' (aka 'struct __CFMyErrorRef *') bridges to MyError, not 'id<P1,P2,P4>'}} |
| 97 | } |
| 98 | |
| 99 | void Test5(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) { |
| 100 | (void)(CFErrorRef)ID; // ok |
| 101 | (void)(CFErrorRef)P123; // ok |
| 102 | (void)(CFErrorRef)P1234; // ok |
| Fariborz Jahanian | 48a01cb | 2014-04-04 23:53:45 +0000 | [diff] [blame] | 103 | (void)(CFErrorRef)P12; // ok |
| 104 | (void)(CFErrorRef)P23; // ok |
| Fariborz Jahanian | 92ab298 | 2013-11-20 00:32:12 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void Test6(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) { |
| 108 | |
| 109 | (void)(CFMyErrorRef)ID; // ok |
| 110 | (void)(CFMyErrorRef)P123; // ok |
| 111 | (void)(CFMyErrorRef)P1234; // ok |
| Fariborz Jahanian | 48a01cb | 2014-04-04 23:53:45 +0000 | [diff] [blame] | 112 | (void)(CFMyErrorRef)P12; // ok |
| 113 | (void)(CFMyErrorRef)P23; // ok |
| Fariborz Jahanian | 92ab298 | 2013-11-20 00:32:12 +0000 | [diff] [blame] | 114 | } |
| Fariborz Jahanian | 91fb0be | 2013-11-20 19:01:50 +0000 | [diff] [blame] | 115 | |
| Fariborz Jahanian | 48a01cb | 2014-04-04 23:53:45 +0000 | [diff] [blame] | 116 | typedef struct __attribute__ ((objc_bridge(MyPersonalError))) __CFMyPersonalErrorRef * CFMyPersonalErrorRef; // expected-note 1 {{declared here}} |
| Fariborz Jahanian | 91fb0be | 2013-11-20 19:01:50 +0000 | [diff] [blame] | 117 | |
| Fariborz Jahanian | 48a01cb | 2014-04-04 23:53:45 +0000 | [diff] [blame] | 118 | @interface MyPersonalError : NSError <P4> // expected-note 1 {{declared here}} |
| Fariborz Jahanian | 91fb0be | 2013-11-20 19:01:50 +0000 | [diff] [blame] | 119 | @end |
| 120 | |
| 121 | void Test7(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) { |
| 122 | (void)(CFMyPersonalErrorRef)ID; // ok |
| Fariborz Jahanian | 48a01cb | 2014-04-04 23:53:45 +0000 | [diff] [blame] | 123 | (void)(CFMyPersonalErrorRef)P123; // ok |
| Fariborz Jahanian | 91fb0be | 2013-11-20 19:01:50 +0000 | [diff] [blame] | 124 | (void)(CFMyPersonalErrorRef)P1234; // ok |
| Fariborz Jahanian | 48a01cb | 2014-04-04 23:53:45 +0000 | [diff] [blame] | 125 | (void)(CFMyPersonalErrorRef)P12; // ok |
| 126 | (void)(CFMyPersonalErrorRef)P23; // ok |
| Fariborz Jahanian | 91fb0be | 2013-11-20 19:01:50 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | void Test8(CFMyPersonalErrorRef cf) { |
| 130 | (void)(id)cf; // ok |
| 131 | (void)(id<P1>)cf; // ok |
| 132 | (void)(id<P1, P2>)cf; // ok |
| 133 | (void)(id<P1, P2, P3>)cf; // ok |
| 134 | (void)(id<P1, P2, P3, P4>)cf; // ok |
| 135 | (void)(id<P1, P2, P3, P4, P5>)cf; // expected-warning {{'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *') bridges to MyPersonalError, not 'id<P1,P2,P3,P4,P5>'}} |
| 136 | } |
| Fariborz Jahanian | f1a22f4 | 2014-04-29 16:12:56 +0000 | [diff] [blame] | 137 | |
| 138 | CFDictionaryRef bar() __attribute__((cf_returns_not_retained)); |
| 139 | @class NSNumber; |
| 140 | |
| 141 | void Test9() { |
| 142 | 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}} |
| 143 | } |
| Fariborz Jahanian | 27aa9b4 | 2015-04-10 22:07:47 +0000 | [diff] [blame] | 144 | |
| 145 | // rdar://18311183 |
| 146 | @interface NSObject @end |
| 147 | |
| 148 | @interface NSFont : NSObject @end |
| 149 | |
| 150 | typedef struct __attribute__ ((objc_bridge(NSFont))) __CFFontRef * CFFontRef; |
| 151 | |
| 152 | void Test10(CFFontRef cf) { |
| 153 | (void)(__bridge NSObject *)cf; |
| 154 | } |