Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 71a8d8c

Browse files
author
Fariborz Jahanian
committed
ObjectiveC. Allow toll free bridge cast warnings outside
ARC and in objectiveC/ObjectiveC++ MRR mode as well. // rdar://15454846 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195288 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6e40f59 commit 71a8d8c

File tree

7 files changed

+429
-24
lines changed

7 files changed

+429
-24
lines changed

include/clang/Sema/Sema.h

+2
Original file line numberDiff line numberDiff line change
@@ -6865,6 +6865,8 @@ class Sema {
68656865
SourceLocation RParenLoc,
68666866
Expr *SubExpr);
68676867

6868+
void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr);
6869+
68686870
bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall);
68696871

68706872
/// \brief Check whether the given new method is a valid override of the

lib/Sema/SemaCast.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,8 @@ void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle,
20742074

20752075
if (Self.getLangOpts().ObjCAutoRefCount && tcr == TC_Success)
20762076
checkObjCARCConversion(CCK);
2077+
else if (Self.getLangOpts().ObjC1 && tcr == TC_Success)
2078+
Self.CheckTollFreeBridgeCast(DestType, SrcExpr.get());
20772079

20782080
if (tcr != TC_Success && msg != 0) {
20792081
if (SrcExpr.get()->getType() == Self.Context.OverloadTy) {
@@ -2319,6 +2321,9 @@ void CastOperation::CheckCStyleCast() {
23192321
return;
23202322
}
23212323
}
2324+
else if (Self.getLangOpts().ObjC1)
2325+
Self.CheckTollFreeBridgeCast(DestType, SrcExpr.get());
2326+
23222327
DiagnoseCastOfObjCSEL(Self, SrcExpr, DestType);
23232328
DiagnoseBadFunctionCast(Self, SrcExpr, DestType);
23242329
Kind = Self.PrepareScalarCast(SrcExpr, DestType);

lib/Sema/SemaExprObjC.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,16 @@ static bool CheckObjCBridgeCFCast(Sema &S, QualType castType, Expr *castExpr) {
32853285
return false;
32863286
}
32873287

3288+
void Sema::CheckTollFreeBridgeCast(QualType castType, Expr *castExpr) {
3289+
// warn in presense of __bridge casting to or from a toll free bridge cast.
3290+
ARCConversionTypeClass exprACTC = classifyTypeForARCConversion(castExpr->getType());
3291+
ARCConversionTypeClass castACTC = classifyTypeForARCConversion(castType);
3292+
if (castACTC == ACTC_retainable && exprACTC == ACTC_coreFoundation)
3293+
(void)CheckObjCBridgeNSCast(*this, castType, castExpr);
3294+
else if (castACTC == ACTC_coreFoundation && exprACTC == ACTC_retainable)
3295+
(void)CheckObjCBridgeCFCast(*this, castType, castExpr);
3296+
}
3297+
32883298
Sema::ARCConversionResult
32893299
Sema::CheckObjCARCConversion(SourceRange castRange, QualType castType,
32903300
Expr *&castExpr, CheckedConversionKind CCK,
@@ -3617,15 +3627,8 @@ ExprResult Sema::ActOnObjCBridgedCast(Scope *S,
36173627
Expr *SubExpr) {
36183628
TypeSourceInfo *TSInfo = 0;
36193629
QualType T = GetTypeFromParser(Type, &TSInfo);
3620-
if (Kind == OBC_Bridge) {
3621-
// warn in presense of __bridge casting to or from a toll free bridge cast.
3622-
ARCConversionTypeClass exprACTC = classifyTypeForARCConversion(SubExpr->getType());
3623-
ARCConversionTypeClass castACTC = classifyTypeForARCConversion(T);
3624-
if (castACTC == ACTC_retainable && exprACTC == ACTC_coreFoundation)
3625-
(void)CheckObjCBridgeNSCast(*this, T, SubExpr);
3626-
else if (castACTC == ACTC_coreFoundation && exprACTC == ACTC_retainable)
3627-
(void)CheckObjCBridgeCFCast(*this, T, SubExpr);
3628-
}
3630+
if (Kind == OBC_Bridge)
3631+
CheckTollFreeBridgeCast(T, SubExpr);
36293632
if (!TSInfo)
36303633
TSInfo = Context.getTrivialTypeSourceInfo(T, LParenLoc);
36313634
return BuildObjCBridgedCast(LParenLoc, Kind, BridgeKeywordLoc, TSInfo,
+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// RUN: %clang_cc1 -fsyntax-only -x objective-c -fobjc-arc -verify -Wno-objc-root-class %s
2+
// rdar://15454846
3+
4+
typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 7 {{declared here}}
5+
6+
typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 3 {{declared here}}
7+
8+
typedef 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+
10+
typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
11+
12+
typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}}
13+
14+
typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{'objc_bridge' attribute only applies to struct or union}}
15+
16+
typedef struct __attribute__((objc_bridge(NSLocale, NSError))) __CFLocale *CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}}
17+
18+
typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}}
19+
20+
typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef;
21+
22+
typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); // expected-error {{'objc_bridge' attribute only applies to struct or union}};
23+
24+
typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; // expected-error {{'objc_bridge' attribute only applies to struct or union}};
25+
26+
typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; // expected-error {{'objc_bridge' attribute only applies to struct or union}};
27+
28+
typedef union __attribute__((objc_bridge(NSUColor))) __CFUPrimeColor XXX;
29+
typedef 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+
40+
typedef struct __attribute__((objc_bridge(NSTesting))) __CFError *CFTestingRef; // expected-note {{declared here}}
41+
42+
id 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+
46+
typedef CFErrorRef CFErrorRef1;
47+
48+
typedef CFErrorRef1 CFErrorRef2; // expected-note 2 {{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 7 {{declared here}}
57+
58+
@interface MyError : NSError // expected-note 3 {{declared here}}
59+
@end
60+
61+
@interface NSUColor @end
62+
63+
@class NSString;
64+
65+
void 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+
77+
void 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+
83+
void 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+
91+
void 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; // expected-warning {{'id<P1,P2>' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
96+
(void)(CFErrorRef)P23; // expected-warning {{'id<P2,P3>' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
97+
}
98+
99+
void 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; // expected-warning {{'id<P1,P2>' cannot bridge to 'CFMyErrorRef' (aka 'struct __CFMyErrorRef *')}}
105+
(void)(CFMyErrorRef)P23; // expected-warning {{'id<P2,P3>' cannot bridge to 'CFMyErrorRef' (aka 'struct __CFMyErrorRef *')}}
106+
}
107+
108+
typedef struct __attribute__ ((objc_bridge(MyPersonalError))) __CFMyPersonalErrorRef * CFMyPersonalErrorRef; // expected-note 4 {{declared here}}
109+
110+
@interface MyPersonalError : NSError <P4> // expected-note 4 {{declared here}}
111+
@end
112+
113+
void 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; // expected-warning {{'id<P1,P2,P3>' cannot bridge to 'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *')}}
116+
(void)(CFMyPersonalErrorRef)P1234; // ok
117+
(void)(CFMyPersonalErrorRef)P12; // expected-warning {{'id<P1,P2>' cannot bridge to 'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *')}}
118+
(void)(CFMyPersonalErrorRef)P23; // expected-warning {{'id<P2,P3>' cannot bridge to 'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *')}}
119+
}
120+
121+
void 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+
130+
void Test9(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
131+
(void)(__bridge NSString *)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'NSString'}}
132+
(void)(__bridge NSError *)cf; // okay
133+
(void)(__bridge MyError*)cf; // okay,
134+
(void)(__bridge NSUColor *)cf2; // okay
135+
(void)(__bridge CFErrorRef)ns; // okay
136+
(void)(__bridge CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
137+
(void)(__bridge Class)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'Class'}}
138+
(void)(__bridge CFErrorRef)c; // expected-warning {{'__unsafe_unretained Class' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
139+
}

test/SemaObjC/objcbridge-attribute.m

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
1+
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
22
// rdar://15454846
33

4-
typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 7 {{declared here}}
4+
typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 5 {{declared here}}
55

66
typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 3 {{declared here}}
77

@@ -45,15 +45,15 @@ id Test1(CFTestingRef cf) {
4545

4646
typedef CFErrorRef CFErrorRef1;
4747

48-
typedef CFErrorRef1 CFErrorRef2; // expected-note 2 {{declared here}}
48+
typedef CFErrorRef1 CFErrorRef2; // expected-note {{declared here}}
4949

5050
@protocol P1 @end
5151
@protocol P2 @end
5252
@protocol P3 @end
5353
@protocol P4 @end
5454
@protocol P5 @end
5555

56-
@interface NSError<P1, P2, P3> @end // expected-note 7 {{declared here}}
56+
@interface NSError<P1, P2, P3> @end // expected-note 5 {{declared here}}
5757

5858
@interface MyError : NSError // expected-note 3 {{declared here}}
5959
@end
@@ -126,14 +126,3 @@ void Test8(CFMyPersonalErrorRef cf) {
126126
(void)(id<P1, P2, P3, P4>)cf; // ok
127127
(void)(id<P1, P2, P3, P4, P5>)cf; // expected-warning {{'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *') bridges to MyPersonalError, not 'id<P1,P2,P3,P4,P5>'}}
128128
}
129-
130-
void Test9(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
131-
(void)(__bridge NSString *)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'NSString'}}
132-
(void)(__bridge NSError *)cf; // okay
133-
(void)(__bridge MyError*)cf; // okay,
134-
(void)(__bridge NSUColor *)cf2; // okay
135-
(void)(__bridge CFErrorRef)ns; // okay
136-
(void)(__bridge CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
137-
(void)(__bridge Class)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'Class'}}
138-
(void)(__bridge CFErrorRef)c; // expected-warning {{'__unsafe_unretained Class' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
139-
}
+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// RUN: %clang_cc1 -fsyntax-only -x objective-c++ -fobjc-arc -verify -Wno-objc-root-class %s
2+
// rdar://15454846
3+
4+
typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 7 {{declared here}}
5+
6+
typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 3 {{declared here}}
7+
8+
typedef 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+
10+
typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
11+
12+
typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{'objc_bridge' attribute only applies to struct, union or class}}
13+
14+
typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{'objc_bridge' attribute only applies to struct, union or class}}
15+
16+
typedef struct __attribute__((objc_bridge(NSLocale, NSError))) __CFLocale *CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}}
17+
18+
typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute only applies to struct, union or class}}
19+
20+
typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef;
21+
22+
typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); // expected-error {{'objc_bridge' attribute only applies to struct, union or class}};
23+
24+
typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; // expected-error {{'objc_bridge' attribute only applies to struct, union or class}};
25+
26+
typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; // expected-error {{'objc_bridge' attribute only applies to struct, union or class}};
27+
28+
typedef union __attribute__((objc_bridge(NSUColor))) __CFUPrimeColor XXX;
29+
typedef XXX *CFUColor2Ref;
30+
31+
@interface I
32+
{
33+
__attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to struct, union or class}};
34+
}
35+
@end
36+
37+
@protocol NSTesting @end
38+
@class NSString;
39+
40+
typedef struct __attribute__((objc_bridge(NSTesting))) __CFError *CFTestingRef; // expected-note {{declared here}}
41+
42+
id Test1(CFTestingRef cf) {
43+
return (NSString *)cf; // expected-error {{CF object of type 'CFTestingRef' (aka '__CFError *') is bridged to 'NSTesting', which is not an Objective-C class}}
44+
}
45+
46+
typedef CFErrorRef CFErrorRef1;
47+
48+
typedef CFErrorRef1 CFErrorRef2; // expected-note 2 {{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 7 {{declared here}}
57+
58+
@interface MyError : NSError // expected-note 3 {{declared here}}
59+
@end
60+
61+
@interface NSUColor @end
62+
63+
@class NSString;
64+
65+
void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
66+
(void)(NSString *)cf; // expected-warning {{'CFErrorRef2' (aka '__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 '__CFErrorRef *')}}
72+
(void)(Class)cf; // expected-warning {{'CFErrorRef2' (aka '__CFErrorRef *') bridges to NSError, not 'Class'}}
73+
(void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef'}}
74+
}
75+
76+
77+
void 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 '__CFErrorRef *') bridges to NSError, not 'id<P1,P2,P4>'}}
81+
}
82+
83+
void 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 '__CFMyErrorRef *') bridges to MyError, not 'id<P1,P2,P4>'}}
89+
}
90+
91+
void 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; // expected-warning {{'id<P1,P2>' cannot bridge to 'CFErrorRef' (aka '__CFErrorRef *')}}
96+
(void)(CFErrorRef)P23; // expected-warning {{'id<P2,P3>' cannot bridge to 'CFErrorRef' (aka '__CFErrorRef *')}}
97+
}
98+
99+
void 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; // expected-warning {{'id<P1,P2>' cannot bridge to 'CFMyErrorRef' (aka '__CFMyErrorRef *')}}
105+
(void)(CFMyErrorRef)P23; // expected-warning {{'id<P2,P3>' cannot bridge to 'CFMyErrorRef' (aka '__CFMyErrorRef *')}}
106+
}
107+
108+
typedef struct __attribute__ ((objc_bridge(MyPersonalError))) __CFMyPersonalErrorRef * CFMyPersonalErrorRef; // expected-note 4 {{declared here}}
109+
110+
@interface MyPersonalError : NSError <P4> // expected-note 4 {{declared here}}
111+
@end
112+
113+
void 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; // expected-warning {{'id<P1,P2,P3>' cannot bridge to 'CFMyPersonalErrorRef' (aka '__CFMyPersonalErrorRef *')}}
116+
(void)(CFMyPersonalErrorRef)P1234; // ok
117+
(void)(CFMyPersonalErrorRef)P12; // expected-warning {{'id<P1,P2>' cannot bridge to 'CFMyPersonalErrorRef' (aka '__CFMyPersonalErrorRef *')}}
118+
(void)(CFMyPersonalErrorRef)P23; // expected-warning {{'id<P2,P3>' cannot bridge to 'CFMyPersonalErrorRef' (aka '__CFMyPersonalErrorRef *')}}
119+
}
120+
121+
void 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 '__CFMyPersonalErrorRef *') bridges to MyPersonalError, not 'id<P1,P2,P3,P4,P5>'}}
128+
}
129+
130+
void Test9(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
131+
(void)(__bridge NSString *)cf; // expected-warning {{'CFErrorRef2' (aka '__CFErrorRef *') bridges to NSError, not 'NSString'}}
132+
(void)(__bridge NSError *)cf; // okay
133+
(void)(__bridge MyError*)cf; // okay,
134+
(void)(__bridge NSUColor *)cf2; // okay
135+
(void)(__bridge CFErrorRef)ns; // okay
136+
(void)(__bridge CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka '__CFErrorRef *')}}
137+
(void)(__bridge Class)cf; // expected-warning {{'CFErrorRef2' (aka '__CFErrorRef *') bridges to NSError, not 'Class'}}
138+
(void)(__bridge CFErrorRef)c; // expected-warning {{'__unsafe_unretained Class' cannot bridge to 'CFErrorRef' (aka '__CFErrorRef *')}}
139+
}

0 commit comments

Comments
 (0)