blob: d39861f0613239b729d75acff3a445310dca65c5 [file] [log] [blame]
Fariborz Jahaniana649c822013-11-15 22:18:17 +00001// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +00002// rdar://15454846
3
Fariborz Jahanian2c312122013-11-16 23:22:37 +00004typedef struct __CFErrorRef * __attribute__ ((objc_bridge(NSError))) CFErrorRef; // expected-note 2 {{declared here}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +00005
Fariborz Jahanianae02d152013-11-14 00:43:05 +00006typedef 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 Jahanian0a0a3972013-11-13 23:59:17 +00007
Fariborz Jahanianae02d152013-11-14 00:43:05 +00008typedef struct __CFArray * __attribute__ ((objc_bridge)) CFArrayRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +00009
Fariborz Jahanianb8233192013-11-15 23:14:45 +000010typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000011
Fariborz Jahanianb8233192013-11-15 23:14:45 +000012typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000013
Fariborz Jahaniana0f03952013-11-14 01:00:26 +000014typedef struct __CFLocale * __attribute__((objc_bridge(NSLocale, NSError))) CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000015
Fariborz Jahanianb8233192013-11-15 23:14:45 +000016typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000017
Fariborz Jahaniana0f03952013-11-14 01:00:26 +000018typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef; // expected-error {{'objc_bridge' attribute must be put on a typedef only}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000019
Fariborz Jahaniana0f03952013-11-14 01:00:26 +000020typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet)));
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000021
Fariborz Jahanianb8233192013-11-15 23:14:45 +000022typedef union __CFUColor * __attribute__((objc_bridge(NSUColor))) CFUColorRef; // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000023
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 Jahaniana649c822013-11-15 22:18:17 +000030
31@protocol NSTesting @end
32@class NSString;
33
34typedef struct __CFError * __attribute__((objc_bridge(NSTesting))) CFTestingRef; // expected-note {{declared here}}
35
Fariborz Jahaniane79cef62013-11-15 22:33:12 +000036id Test1(CFTestingRef cf) {
Fariborz Jahanianb8233192013-11-15 23:14:45 +000037 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 Jahaniana649c822013-11-15 22:18:17 +000038}
Fariborz Jahaniane79cef62013-11-15 22:33:12 +000039
40typedef CFErrorRef CFErrorRef1;
41
42typedef CFErrorRef1 CFErrorRef2;
43
44@interface NSError @end
45
46@interface MyError : NSError
47@end
48
49@class NSString;
50
Fariborz Jahanian2c312122013-11-16 23:22:37 +000051void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c) {
Fariborz Jahanianf07183c2013-11-16 01:45:25 +000052 (void)(NSString *)cf; // expected-warning {{CFErrorRef bridges to NSError, not NSString}}
53 (void)(NSError *)cf; // okay
54 (void)(MyError*)cf; // okay,
Fariborz Jahanian8a0210e2013-11-16 19:16:32 +000055 (void)(CFErrorRef)ns; // okay
56 (void)(CFErrorRef)str; // expected-warning {{NSString cannot bridge to CFErrorRef}}
Fariborz Jahanian2c312122013-11-16 23:22:37 +000057 (void)(Class)cf; // expected-warning {{CFErrorRef bridges to NSError, not 'Class'}}
58 (void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef'}}
Fariborz Jahaniane79cef62013-11-15 22:33:12 +000059}