blob: c5bf9f843d5170572f73bd98acd8227cd3a62808 [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 Jahanian92ab2982013-11-20 00:32:12 +00004typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 5 {{declared here}}
5
6typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 3 {{declared here}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +00007
Fariborz Jahaniandb3d8552013-11-19 00:09:48 +00008typedef 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 Jahanian0a0a3972013-11-13 23:59:17 +00009
Fariborz Jahaniandb3d8552013-11-19 00:09:48 +000010typedef struct __attribute__ ((objc_bridge)) __CFArray *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 +000011
Fariborz Jahanianf720f862013-11-19 17:42:25 +000012typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000013
Fariborz Jahanianf720f862013-11-19 17:42:25 +000014typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{'objc_bridge' attribute only applies to struct or union}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000015
Fariborz Jahaniandb3d8552013-11-19 00:09:48 +000016typedef struct __attribute__((objc_bridge(NSLocale, NSError))) __CFLocale *CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000017
Fariborz Jahanianf720f862013-11-19 17:42:25 +000018typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}}
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000019
Fariborz Jahaniandb3d8552013-11-19 00:09:48 +000020typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef;
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000021
Fariborz Jahanianf720f862013-11-19 17:42:25 +000022typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); // expected-error {{'objc_bridge' attribute only applies to struct or union}};
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000023
Fariborz Jahanianf720f862013-11-19 17:42:25 +000024typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}};
Fariborz Jahaniandb3d8552013-11-19 00:09:48 +000025
Fariborz Jahanianf720f862013-11-19 17:42:25 +000026typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; // expected-error {{'objc_bridge' attribute only applies to struct or union}};
Fariborz Jahaniandb3d8552013-11-19 00:09:48 +000027
28typedef union __attribute__((objc_bridge(NSUColor))) __CFUPrimeColor XXX;
29typedef XXX *CFUColor2Ref;
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000030
31@interface I
32{
Fariborz Jahanianf720f862013-11-19 17:42:25 +000033 __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to struct or union}};
Fariborz Jahanian0a0a3972013-11-13 23:59:17 +000034}
35@end
Fariborz Jahaniana649c822013-11-15 22:18:17 +000036
37@protocol NSTesting @end
38@class NSString;
39
Fariborz Jahaniandb3d8552013-11-19 00:09:48 +000040typedef struct __attribute__((objc_bridge(NSTesting))) __CFError *CFTestingRef; // expected-note {{declared here}}
Fariborz Jahaniana649c822013-11-15 22:18:17 +000041
Fariborz Jahaniane79cef62013-11-15 22:33:12 +000042id Test1(CFTestingRef cf) {
Fariborz Jahanianb8233192013-11-15 23:14:45 +000043 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 +000044}
Fariborz Jahaniane79cef62013-11-15 22:33:12 +000045
46typedef CFErrorRef CFErrorRef1;
47
Fariborz Jahanian92ab2982013-11-20 00:32:12 +000048typedef CFErrorRef1 CFErrorRef2; // expected-note {{declared here}}
Fariborz Jahaniane79cef62013-11-15 22:33:12 +000049
Fariborz Jahanian92ab2982013-11-20 00:32:12 +000050@protocol P1 @end
51@protocol P2 @end
52@protocol P3 @end
53@protocol P4 @end
Fariborz Jahaniane79cef62013-11-15 22:33:12 +000054
Fariborz Jahanian92ab2982013-11-20 00:32:12 +000055@interface NSError<P1, P2, P3> @end // expected-note 5 {{declared here}}
56
57@interface MyError : NSError // expected-note 3 {{declared here}}
Fariborz Jahaniane79cef62013-11-15 22:33:12 +000058@end
59
Fariborz Jahaniandb3d8552013-11-19 00:09:48 +000060@interface NSUColor @end
61
Fariborz Jahaniane79cef62013-11-15 22:33:12 +000062@class NSString;
63
Fariborz Jahaniandb3d8552013-11-19 00:09:48 +000064void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
Fariborz Jahanian509f31e2013-11-19 01:23:07 +000065 (void)(NSString *)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'NSString'}}
Fariborz Jahanianf07183c2013-11-16 01:45:25 +000066 (void)(NSError *)cf; // okay
67 (void)(MyError*)cf; // okay,
Fariborz Jahaniandb3d8552013-11-19 00:09:48 +000068 (void)(NSUColor *)cf2; // okay
Fariborz Jahanian8a0210e2013-11-16 19:16:32 +000069 (void)(CFErrorRef)ns; // okay
Fariborz Jahanian509f31e2013-11-19 01:23:07 +000070 (void)(CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
71 (void)(Class)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'Class'}}
Fariborz Jahanian2c312122013-11-16 23:22:37 +000072 (void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef'}}
Fariborz Jahaniane79cef62013-11-15 22:33:12 +000073}
Fariborz Jahanian92ab2982013-11-20 00:32:12 +000074
75
76void Test3(CFErrorRef cf, NSError *ns) {
77 (void)(id)cf; // okay
78 (void)(id<P1, P2>)cf; // okay
79 (void)(id<P1, P2, P4>)cf; // expected-warning {{'CFErrorRef' (aka 'struct __CFErrorRef *') bridges to NSError, not 'id<P1,P2,P4>'}}
80}
81
82void Test4(CFMyErrorRef cf) {
83 (void)(id)cf; // okay
84 (void)(id<P1, P2>)cf; // ok
85 (void)(id<P1, P2, P3>)cf; // ok
86 (void)(id<P2, P3>)cf; // ok
87 (void)(id<P1, P2, P4>)cf; // expected-warning {{'CFMyErrorRef' (aka 'struct __CFMyErrorRef *') bridges to MyError, not 'id<P1,P2,P4>'}}
88}
89
90void Test5(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) {
91 (void)(CFErrorRef)ID; // ok
92 (void)(CFErrorRef)P123; // ok
93 (void)(CFErrorRef)P1234; // ok
94 (void)(CFErrorRef)P12; // expected-warning {{'id<P1,P2>' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
95 (void)(CFErrorRef)P23; // expected-warning {{'id<P2,P3>' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
96}
97
98void Test6(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) {
99
100 (void)(CFMyErrorRef)ID; // ok
101 (void)(CFMyErrorRef)P123; // ok
102 (void)(CFMyErrorRef)P1234; // ok
103 (void)(CFMyErrorRef)P12; // expected-warning {{'id<P1,P2>' cannot bridge to 'CFMyErrorRef' (aka 'struct __CFMyErrorRef *')}}
104 (void)(CFMyErrorRef)P23; // expected-warning {{'id<P2,P3>' cannot bridge to 'CFMyErrorRef' (aka 'struct __CFMyErrorRef *')}}
105}