xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjC/compare-qualified-class.m (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc// rdar://8191774
3f4a2713aSLionel Sambuc
4f4a2713aSLionel Sambuc@protocol SomeProtocol
5f4a2713aSLionel Sambuc@end
6f4a2713aSLionel Sambuc
7f4a2713aSLionel Sambuc@protocol SomeProtocol1
8f4a2713aSLionel Sambuc@end
9f4a2713aSLionel Sambuc
10f4a2713aSLionel Sambuc@interface SomeObject <SomeProtocol>
11f4a2713aSLionel Sambuc@end
12f4a2713aSLionel Sambuc
13f4a2713aSLionel Sambucint main () {
14f4a2713aSLionel Sambuc    Class <SomeProtocol> classA;
15f4a2713aSLionel Sambuc    Class <SomeProtocol> classB;
16f4a2713aSLionel Sambuc    Class <SomeProtocol, SomeProtocol1> classC;
17f4a2713aSLionel Sambuc    Class <SomeProtocol1> classD;
18f4a2713aSLionel Sambuc    void * pv = 0;
19f4a2713aSLionel Sambuc    Class c = (Class)0;;
20f4a2713aSLionel Sambuc    if (pv)
21f4a2713aSLionel Sambuc      return classA == pv;
22f4a2713aSLionel Sambuc
23f4a2713aSLionel Sambuc    if (c)
24f4a2713aSLionel Sambuc      return classA == c;
25f4a2713aSLionel Sambuc
26f4a2713aSLionel Sambuc    return classA == classB  || classA == classC ||
27f4a2713aSLionel Sambuc           classC == classA ||
28*0a6a1f1dSLionel Sambuc           classA == classD; // expected-warning {{comparison of distinct pointer types ('Class<SomeProtocol>' and 'Class<SomeProtocol1>')}}
29f4a2713aSLionel Sambuc}
30f4a2713aSLionel Sambuc
31*0a6a1f1dSLionel Sambuc// rdar://18491222
32*0a6a1f1dSLionel Sambuc@protocol NSObject @end
33*0a6a1f1dSLionel Sambuc
34*0a6a1f1dSLionel Sambuc@interface NSObject @end
35*0a6a1f1dSLionel Sambuc@protocol ProtocolX <NSObject>
36*0a6a1f1dSLionel Sambuc@end
37*0a6a1f1dSLionel Sambuc
38*0a6a1f1dSLionel Sambuc@protocol ProtocolY <NSObject>
39*0a6a1f1dSLionel Sambuc@end
40*0a6a1f1dSLionel Sambuc
41*0a6a1f1dSLionel Sambuc@interface ClassA : NSObject
42*0a6a1f1dSLionel Sambuc@end
43*0a6a1f1dSLionel Sambuc
44*0a6a1f1dSLionel Sambuc@interface ClassB : ClassA <ProtocolY, ProtocolX>
45*0a6a1f1dSLionel Sambuc@end
46*0a6a1f1dSLionel Sambuc
47*0a6a1f1dSLionel Sambuc@interface OtherClass : NSObject
48*0a6a1f1dSLionel Sambuc@property (nonatomic, copy) ClassB<ProtocolX> *aProperty;
49*0a6a1f1dSLionel Sambuc- (ClassA<ProtocolY> *)aMethod;
50*0a6a1f1dSLionel Sambuc- (ClassA<ProtocolY> *)anotherMethod;
51*0a6a1f1dSLionel Sambuc@end
52*0a6a1f1dSLionel Sambuc
53*0a6a1f1dSLionel Sambuc@implementation OtherClass
54*0a6a1f1dSLionel Sambuc- (ClassA<ProtocolY> *)aMethod {
55*0a6a1f1dSLionel Sambuc    // This does not work, even though ClassB subclasses from A and conforms to Y
56*0a6a1f1dSLionel Sambuc    // because the property type explicity adds ProtocolX conformance
57*0a6a1f1dSLionel Sambuc    // even though ClassB already conforms to ProtocolX
58*0a6a1f1dSLionel Sambuc    return self.aProperty;
59*0a6a1f1dSLionel Sambuc}
60*0a6a1f1dSLionel Sambuc- (ClassA<ProtocolY> *)anotherMethod {
61*0a6a1f1dSLionel Sambuc    // This works, even though all it is doing is removing an explicit
62*0a6a1f1dSLionel Sambuc    // protocol conformance that ClassB already conforms to
63*0a6a1f1dSLionel Sambuc    return (ClassB *)self.aProperty;
64*0a6a1f1dSLionel Sambuc}
65*0a6a1f1dSLionel Sambuc@end
66