1// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
2// rdar://15454846
3
4typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 3 {{declared here}}
5
6typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 1 {{declared here}}
7
8typedef struct __attribute__((objc_bridge(12))) __CFMyColor  *CFMyColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
9
10typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{'objc_bridge' attribute takes one argument}}
11
12typedef void *  __attribute__ ((objc_bridge(NSURL))) CFURLRef;  // expected-error {{'objc_bridge' attribute only applies to struct or union}}
13
14typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{'objc_bridge' attribute only applies to struct or union}}
15
16typedef struct __attribute__((objc_bridge(NSLocale, NSError))) __CFLocale *CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}}
17
18typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}}
19
20typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef; // expected-note {{declared here}}
21
22typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); // expected-error {{'objc_bridge' attribute only applies to struct or union}};
23
24typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}};
25
26typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; // expected-error {{'objc_bridge' attribute only applies to struct or union}};
27
28typedef union __attribute__((objc_bridge(NSUColor))) __CFUPrimeColor XXX;
29typedef XXX *CFUColor2Ref;
30
31@interface I
32{
33   __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to struct or union}};
34}
35@end
36
37@protocol NSTesting @end
38@class NSString;
39
40typedef struct __attribute__((objc_bridge(NSTesting))) __CFError *CFTestingRef; // expected-note {{declared here}}
41
42id Test1(CFTestingRef cf) {
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}}
44}
45
46typedef CFErrorRef CFErrorRef1;
47
48typedef CFErrorRef1 CFErrorRef2; // expected-note {{declared here}}
49
50@protocol P1 @end
51@protocol P2 @end
52@protocol P3 @end
53@protocol P4 @end
54@protocol P5 @end
55
56@interface NSError<P1, P2, P3> @end // expected-note 3 {{declared here}}
57
58@interface MyError : NSError // expected-note 1 {{declared here}}
59@end
60
61@interface NSUColor @end
62
63@class NSString;
64
65void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
66  (void)(NSString *)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'NSString'}}
67  (void)(NSError *)cf; // okay
68  (void)(MyError*)cf; // okay,
69  (void)(NSUColor *)cf2; // okay
70  (void)(CFErrorRef)ns; // okay
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'}}
73  (void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef'}}
74}
75
76
77void 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
83void 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
91void 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; // ok
96 (void)(CFErrorRef)P23; // ok
97}
98
99void 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; // ok
105 (void)(CFMyErrorRef)P23; // ok
106}
107
108typedef struct __attribute__ ((objc_bridge(MyPersonalError))) __CFMyPersonalErrorRef * CFMyPersonalErrorRef;  // expected-note 1 {{declared here}}
109
110@interface MyPersonalError : NSError <P4> // expected-note 1 {{declared here}}
111@end
112
113void 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; // ok
116 (void)(CFMyPersonalErrorRef)P1234; // ok
117 (void)(CFMyPersonalErrorRef)P12; // ok
118 (void)(CFMyPersonalErrorRef)P23; // ok
119}
120
121void 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
130CFDictionaryRef bar() __attribute__((cf_returns_not_retained));
131@class NSNumber;
132
133void Test9() {
134  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}}
135}
136