xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjCXX/objcbridge-static-cast.mm (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -x objective-c++ -fobjc-arc -verify -Wno-objc-root-class %s
2*0a6a1f1dSLionel Sambuc// rdar://16756639
3*0a6a1f1dSLionel Sambuc
4*0a6a1f1dSLionel Sambuctypedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 3 {{declared here}}
5*0a6a1f1dSLionel Sambuc
6*0a6a1f1dSLionel Sambuctypedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 1 {{declared here}}
7*0a6a1f1dSLionel Sambuc
8*0a6a1f1dSLionel Sambuctypedef 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*0a6a1f1dSLionel Sambuc
10*0a6a1f1dSLionel Sambuctypedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{'objc_bridge' attribute takes one argument}}
11*0a6a1f1dSLionel Sambuc
12*0a6a1f1dSLionel Sambuctypedef struct __attribute__((objc_bridge(NSLocale, NSError))) __CFLocale *CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}}
13*0a6a1f1dSLionel Sambuc
14*0a6a1f1dSLionel Sambuctypedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef;
15*0a6a1f1dSLionel Sambuc
16*0a6a1f1dSLionel Sambuctypedef union __attribute__((objc_bridge(NSUColor))) __CFUPrimeColor XXX;
17*0a6a1f1dSLionel Sambuctypedef XXX *CFUColor2Ref;
18*0a6a1f1dSLionel Sambuc
19*0a6a1f1dSLionel Sambuc@interface I
20*0a6a1f1dSLionel Sambuc{
21*0a6a1f1dSLionel Sambuc}
22*0a6a1f1dSLionel Sambuc@end
23*0a6a1f1dSLionel Sambuc
24*0a6a1f1dSLionel Sambuc@protocol NSTesting @end
25*0a6a1f1dSLionel Sambuc@class NSString;
26*0a6a1f1dSLionel Sambuc
27*0a6a1f1dSLionel Sambuctypedef struct __attribute__((objc_bridge(NSTesting))) __CFError *CFTestingRef; // expected-note {{declared here}}
28*0a6a1f1dSLionel Sambuc
29*0a6a1f1dSLionel Sambucid Test1(CFTestingRef cf) {
30*0a6a1f1dSLionel Sambuc  return static_cast<NSString *>(cf); // expected-error {{CF object of type 'CFTestingRef' (aka '__CFError *') is bridged to 'NSTesting', which is not an Objective-C class}} \
31*0a6a1f1dSLionel Sambuc                         // expected-error {{cast of C pointer type 'CFTestingRef' (aka '__CFError *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \
32*0a6a1f1dSLionel Sambuc			 // expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
33*0a6a1f1dSLionel Sambuc                         // expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFTestingRef' (aka '__CFError *') into ARC}}
34*0a6a1f1dSLionel Sambuc}
35*0a6a1f1dSLionel Sambuc
36*0a6a1f1dSLionel Sambuctypedef CFErrorRef CFErrorRef1;
37*0a6a1f1dSLionel Sambuc
38*0a6a1f1dSLionel Sambuctypedef CFErrorRef1 CFErrorRef2; // expected-note 1 {{declared here}}
39*0a6a1f1dSLionel Sambuc
40*0a6a1f1dSLionel Sambuc@protocol P1 @end
41*0a6a1f1dSLionel Sambuc@protocol P2 @end
42*0a6a1f1dSLionel Sambuc@protocol P3 @end
43*0a6a1f1dSLionel Sambuc@protocol P4 @end
44*0a6a1f1dSLionel Sambuc@protocol P5 @end
45*0a6a1f1dSLionel Sambuc
46*0a6a1f1dSLionel Sambuc@interface NSError<P1, P2, P3> @end // expected-note 3 {{declared here}}
47*0a6a1f1dSLionel Sambuc
48*0a6a1f1dSLionel Sambuc@interface MyError : NSError // expected-note 1 {{declared here}}
49*0a6a1f1dSLionel Sambuc@end
50*0a6a1f1dSLionel Sambuc
51*0a6a1f1dSLionel Sambuc@interface NSUColor @end
52*0a6a1f1dSLionel Sambuc
53*0a6a1f1dSLionel Sambuc@class NSString;
54*0a6a1f1dSLionel Sambuc
55*0a6a1f1dSLionel Sambucvoid Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
56*0a6a1f1dSLionel Sambuc  (void)static_cast<NSString *>(cf); // expected-warning {{'CFErrorRef2' (aka '__CFErrorRef *') bridges to NSError, not 'NSString'}} \
57*0a6a1f1dSLionel Sambuc                        // expected-error {{cast of C pointer type 'CFErrorRef2' (aka '__CFErrorRef *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \
58*0a6a1f1dSLionel Sambuc                        // expected-note {{__bridge with C-style cast to convert directly (no change in ownership)}} \
59*0a6a1f1dSLionel Sambuc                        // expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFErrorRef2' (aka '__CFErrorRef *') into ARC}}
60*0a6a1f1dSLionel Sambuc  (void)static_cast<NSError *>(cf); // expected-error {{cast of C pointer type 'CFErrorRef2' (aka '__CFErrorRef *') to Objective-C pointer type 'NSError *' requires a bridged cast}} \
61*0a6a1f1dSLionel Sambuc                       // expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
62*0a6a1f1dSLionel Sambuc                       // expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFErrorRef2' (aka '__CFErrorRef *') into ARC}}
63*0a6a1f1dSLionel Sambuc  (void)static_cast<MyError*>(cf); // expected-error {{cast of C pointer type 'CFErrorRef2' (aka '__CFErrorRef *') to Objective-C pointer type 'MyError *' requires a bridged cast}} \
64*0a6a1f1dSLionel Sambuc                        // expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
65*0a6a1f1dSLionel Sambuc                        // expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFErrorRef2' (aka '__CFErrorRef *') into ARC}}
66*0a6a1f1dSLionel Sambuc  (void)static_cast<NSUColor *>(cf2); // expected-error {{cast of C pointer type 'CFUColor2Ref' (aka '__CFUPrimeColor *') to Objective-C pointer type 'NSUColor *' requires a bridged cast}} \
67*0a6a1f1dSLionel Sambuc                         // expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
68*0a6a1f1dSLionel Sambuc                         // expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFUColor2Ref' (aka '__CFUPrimeColor *') into ARC}}
69*0a6a1f1dSLionel Sambuc  (void)static_cast<CFErrorRef>(ns); // expected-error {{cast of Objective-C pointer type 'NSError *' to C pointer type 'CFErrorRef' (aka '__CFErrorRef *') requires a bridged cast}} \
70*0a6a1f1dSLionel Sambuc                        // expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
71*0a6a1f1dSLionel Sambuc 			// expected-note {{use __bridge_retained with C-style cast to make an ARC object available as a +1 'CFErrorRef' (aka '__CFErrorRef *')}}
72*0a6a1f1dSLionel Sambuc  (void)static_cast<CFErrorRef>(str);  // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka '__CFErrorRef *')}} \\
73*0a6a1f1dSLionel Sambuc                          // expected-error {{cast of Objective-C pointer type 'NSString *' to C pointer type 'CFErrorRef' (aka '__CFErrorRef *') requires a bridged cast}} \
74*0a6a1f1dSLionel Sambuc                        // expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
75*0a6a1f1dSLionel Sambuc 			// expected-note {{use __bridge_retained with C-style cast to make an ARC object available as a +1 'CFErrorRef' (aka '__CFErrorRef *')}}
76*0a6a1f1dSLionel Sambuc  (void)static_cast<Class>(cf); // expected-warning {{'CFErrorRef2' (aka '__CFErrorRef *') bridges to NSError, not 'Class'}} \\
77*0a6a1f1dSLionel Sambuc                   // expected-error {{cast of C pointer type 'CFErrorRef2' (aka '__CFErrorRef *') to Objective-C pointer type 'Class' requires a bridged cast}} \
78*0a6a1f1dSLionel Sambuc 			// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
79*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFErrorRef2' (aka '__CFErrorRef *') into ARC}}
80*0a6a1f1dSLionel Sambuc  (void)static_cast<CFErrorRef>(c); // expected-warning {{'Class' cannot bridge to 'CFErrorRef' (aka '__CFErrorRef *}} \\
81*0a6a1f1dSLionel Sambuc                       // expected-error {{cast of Objective-C pointer type 'Class' to C pointer type 'CFErrorRef' (aka '__CFErrorRef *') requires a bridged cast}} \
82*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
83*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge_retained with C-style cast to make an ARC object available as a +1 'CFErrorRef' (aka '__CFErrorRef *')}}
84*0a6a1f1dSLionel Sambuc}
85*0a6a1f1dSLionel Sambuc
86*0a6a1f1dSLionel Sambuc
87*0a6a1f1dSLionel Sambucvoid Test3(CFErrorRef cf, NSError *ns) {
88*0a6a1f1dSLionel Sambuc  (void)static_cast<id>(cf); // expected-error {{cast of C pointer type 'CFErrorRef' (aka '__CFErrorRef *') to Objective-C pointer type 'id' requires a bridged cast}} \
89*0a6a1f1dSLionel Sambuc		// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
90*0a6a1f1dSLionel Sambuc		// expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFErrorRef' (aka '__CFErrorRef *') into ARC}}
91*0a6a1f1dSLionel Sambuc (void)static_cast< id<P1, P2> >(cf); // expected-error {{cast of C pointer type 'CFErrorRef' (aka '__CFErrorRef *') to Objective-C pointer type 'id<P1,P2>' requires a bridged cast}} \
92*0a6a1f1dSLionel Sambuc		// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
93*0a6a1f1dSLionel Sambuc		// expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFErrorRef' (aka '__CFErrorRef *') into ARC}}
94*0a6a1f1dSLionel Sambuc (void)static_cast< id<P1, P2, P4> >(cf); // expected-warning {{'CFErrorRef' (aka '__CFErrorRef *') bridges to NSError, not 'id<P1,P2,P4>'}} \
95*0a6a1f1dSLionel Sambuc                           // expected-error {{cast of C pointer type 'CFErrorRef' (aka '__CFErrorRef *') to Objective-C pointer type 'id<P1,P2,P4>' requires a bridged cast}} \
96*0a6a1f1dSLionel Sambuc		// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
97*0a6a1f1dSLionel Sambuc		// expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFErrorRef' (aka '__CFErrorRef *') into ARC}}
98*0a6a1f1dSLionel Sambuc}
99*0a6a1f1dSLionel Sambuc
100*0a6a1f1dSLionel Sambucvoid Test4(CFMyErrorRef cf) {
101*0a6a1f1dSLionel Sambuc   (void)static_cast<id>(cf); // expected-error {{cast of C pointer type 'CFMyErrorRef' (aka '__CFMyErrorRef *') to Objective-C pointer type 'id' requires a bridged cast}} \
102*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
103*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFMyErrorRef' (aka '__CFMyErrorRef *') into ARC}}
104*0a6a1f1dSLionel Sambuc (void)static_cast< id<P1, P2> >(cf); // expected-error {{cast of C pointer type 'CFMyErrorRef' (aka '__CFMyErrorRef *') to Objective-C pointer type 'id<P1,P2>' requires a bridged cast}} \
105*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
106*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFMyErrorRef' (aka '__CFMyErrorRef *') into ARC}}
107*0a6a1f1dSLionel Sambuc (void)static_cast< id<P1, P2, P3> >(cf); // expected-error {{cast of C pointer type 'CFMyErrorRef' (aka '__CFMyErrorRef *') to Objective-C pointer type 'id<P1,P2,P3>' requires a bridged cast}} \
108*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
109*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFMyErrorRef' (aka '__CFMyErrorRef *') into ARC}}
110*0a6a1f1dSLionel Sambuc (void)static_cast< id<P2, P3> >(cf); // expected-error {{cast of C pointer type 'CFMyErrorRef' (aka '__CFMyErrorRef *') to Objective-C pointer type 'id<P2,P3>' requires a bridged cast}} \
111*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
112*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFMyErrorRef' (aka '__CFMyErrorRef *') into ARC}}
113*0a6a1f1dSLionel Sambuc (void)static_cast< id<P1, P2, P4> >(cf); // expected-warning {{'CFMyErrorRef' (aka '__CFMyErrorRef *') bridges to MyError, not 'id<P1,P2,P4>'}} \
114*0a6a1f1dSLionel Sambuc                           // expected-error {{cast of C pointer type 'CFMyErrorRef' (aka '__CFMyErrorRef *') to Objective-C pointer type 'id<P1,P2,P4>' requires a bridged cast}} \
115*0a6a1f1dSLionel Sambuc				// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
116*0a6a1f1dSLionel Sambuc				// expected-note {{use __bridge_transfer with C-style cast to transfer ownership of a +1 'CFMyErrorRef' (aka '__CFMyErrorRef *') into ARC}}
117*0a6a1f1dSLionel Sambuc}
118*0a6a1f1dSLionel Sambuc
119*0a6a1f1dSLionel Sambucvoid Test5(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) {
120*0a6a1f1dSLionel Sambuc (void)static_cast<CFErrorRef>(ID); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFErrorRef' (aka '__CFErrorRef *') requires a bridged cast}} \
121*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
122*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge_retained with C-style cast to make an ARC object available as a +1 'CFErrorRef' (aka '__CFErrorRef *')}}
123*0a6a1f1dSLionel Sambuc (void)static_cast<CFErrorRef>(P123); // expected-error {{cast of Objective-C pointer type 'id<P1,P2,P3>' to C pointer type 'CFErrorRef' (aka '__CFErrorRef *') requires a bridged cast}} \
124*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
125*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge_retained with C-style cast to make an ARC object available as a +1 'CFErrorRef' (aka '__CFErrorRef *')}}
126*0a6a1f1dSLionel Sambuc (void)static_cast<CFErrorRef>(P1234); // expected-error {{cast of Objective-C pointer type 'id<P1,P2,P3,P4>' to C pointer type 'CFErrorRef' (aka '__CFErrorRef *') requires a bridged cast}} \
127*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
128*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge_retained with C-style cast to make an ARC object available as a +1 'CFErrorRef' (aka '__CFErrorRef *')}}
129*0a6a1f1dSLionel Sambuc (void)static_cast<CFErrorRef>(P12); // expected-error {{cast of Objective-C pointer type 'id<P1,P2>' to C pointer type 'CFErrorRef' (aka '__CFErrorRef *') requires a bridged cast}} \
130*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
131*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge_retained with C-style cast to make an ARC object available as a +1 'CFErrorRef' (aka '__CFErrorRef *')}}
132*0a6a1f1dSLionel Sambuc (void)static_cast<CFErrorRef>(P23); // expected-error {{cast of Objective-C pointer type 'id<P2,P3>' to C pointer type 'CFErrorRef' (aka '__CFErrorRef *') requires a bridged cast}} \
133*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge with C-style cast to convert directly (no change in ownership)}} \
134*0a6a1f1dSLionel Sambuc			// expected-note {{use __bridge_retained with C-style cast to make an ARC object available as a +1 'CFErrorRef' (aka '__CFErrorRef *')}}
135*0a6a1f1dSLionel Sambuc}
136