| 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 | 2c31212 | 2013-11-16 23:22:37 +0000 | [diff] [blame^] | 4 | typedef struct __CFErrorRef * __attribute__ ((objc_bridge(NSError))) CFErrorRef; // expected-note 2 {{declared here}} | 
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 5 |  | 
| Fariborz Jahanian | ae02d15 | 2013-11-14 00:43:05 +0000 | [diff] [blame] | 6 | typedef struct __CFMyColor  * __attribute__((objc_bridge(12))) 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] | 7 |  | 
| Fariborz Jahanian | ae02d15 | 2013-11-14 00:43:05 +0000 | [diff] [blame] | 8 | typedef struct __CFArray *  __attribute__ ((objc_bridge)) 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] | 9 |  | 
| Fariborz Jahanian | b823319 | 2013-11-15 23:14:45 +0000 | [diff] [blame] | 10 | typedef void *  __attribute__ ((objc_bridge(NSURL))) CFURLRef;  // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}} | 
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 11 |  | 
| Fariborz Jahanian | b823319 | 2013-11-15 23:14:45 +0000 | [diff] [blame] | 12 | typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}} | 
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 13 |  | 
| Fariborz Jahanian | a0f0395 | 2013-11-14 01:00:26 +0000 | [diff] [blame] | 14 | typedef struct __CFLocale * __attribute__((objc_bridge(NSLocale, NSError))) CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}} | 
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 15 |  | 
| Fariborz Jahanian | b823319 | 2013-11-15 23:14:45 +0000 | [diff] [blame] | 16 | typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}} | 
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 17 |  | 
| Fariborz Jahanian | a0f0395 | 2013-11-14 01:00:26 +0000 | [diff] [blame] | 18 | typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef; // expected-error {{'objc_bridge' attribute must be put on a typedef only}} | 
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 19 |  | 
| Fariborz Jahanian | a0f0395 | 2013-11-14 01:00:26 +0000 | [diff] [blame] | 20 | typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); | 
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 21 |  | 
| Fariborz Jahanian | b823319 | 2013-11-15 23:14:45 +0000 | [diff] [blame] | 22 | typedef union __CFUColor * __attribute__((objc_bridge(NSUColor))) CFUColorRef; // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}} | 
| Fariborz Jahanian | 0a0a397 | 2013-11-13 23:59:17 +0000 | [diff] [blame] | 23 |  | 
|  | 24 | @interface I | 
|  | 25 | { | 
|  | 26 | __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute must be put on a typedef only}} | 
|  | 27 |  | 
|  | 28 | } | 
|  | 29 | @end | 
| Fariborz Jahanian | a649c82 | 2013-11-15 22:18:17 +0000 | [diff] [blame] | 30 |  | 
|  | 31 | @protocol NSTesting @end | 
|  | 32 | @class NSString; | 
|  | 33 |  | 
|  | 34 | typedef struct __CFError * __attribute__((objc_bridge(NSTesting))) CFTestingRef; // expected-note {{declared here}} | 
|  | 35 |  | 
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 36 | id Test1(CFTestingRef cf) { | 
| Fariborz Jahanian | b823319 | 2013-11-15 23:14:45 +0000 | [diff] [blame] | 37 | 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] | 38 | } | 
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 39 |  | 
|  | 40 | typedef CFErrorRef CFErrorRef1; | 
|  | 41 |  | 
|  | 42 | typedef CFErrorRef1 CFErrorRef2; | 
|  | 43 |  | 
|  | 44 | @interface NSError @end | 
|  | 45 |  | 
|  | 46 | @interface MyError : NSError | 
|  | 47 | @end | 
|  | 48 |  | 
|  | 49 | @class NSString; | 
|  | 50 |  | 
| Fariborz Jahanian | 2c31212 | 2013-11-16 23:22:37 +0000 | [diff] [blame^] | 51 | void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c) { | 
| Fariborz Jahanian | f07183c | 2013-11-16 01:45:25 +0000 | [diff] [blame] | 52 | (void)(NSString *)cf; // expected-warning {{CFErrorRef bridges to NSError, not NSString}} | 
|  | 53 | (void)(NSError *)cf; // okay | 
|  | 54 | (void)(MyError*)cf; // okay, | 
| Fariborz Jahanian | 8a0210e | 2013-11-16 19:16:32 +0000 | [diff] [blame] | 55 | (void)(CFErrorRef)ns; // okay | 
|  | 56 | (void)(CFErrorRef)str;  // expected-warning {{NSString cannot bridge to CFErrorRef}} | 
| Fariborz Jahanian | 2c31212 | 2013-11-16 23:22:37 +0000 | [diff] [blame^] | 57 | (void)(Class)cf; // expected-warning {{CFErrorRef bridges to NSError, not 'Class'}} | 
|  | 58 | (void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef'}} | 
| Fariborz Jahanian | e79cef6 | 2013-11-15 22:33:12 +0000 | [diff] [blame] | 59 | } |