brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 0f4f7ad Raw
64 lines · plain
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3@protocol SomeProtocol4@end5 6@protocol SomeProtocol17@end8 9@interface SomeObject <SomeProtocol>10@end11 12int main (void) {13    Class <SomeProtocol> classA;14    Class <SomeProtocol> classB;15    Class <SomeProtocol, SomeProtocol1> classC;16    Class <SomeProtocol1> classD;17    void * pv = 0;18    Class c = (Class)0;;19    if (pv)20      return classA == pv;21 22    if (c)23      return classA == c;24    25    return classA == classB  || classA == classC ||26           classC == classA ||27           classA == classD; // expected-warning {{comparison of distinct pointer types ('Class<SomeProtocol>' and 'Class<SomeProtocol1>')}}28}29 30@protocol NSObject @end31 32@interface NSObject @end33@protocol ProtocolX <NSObject>34@end35 36@protocol ProtocolY <NSObject>37@end38 39@interface ClassA : NSObject40@end41 42@interface ClassB : ClassA <ProtocolY, ProtocolX>43@end44 45@interface OtherClass : NSObject46@property (nonatomic, copy) ClassB<ProtocolX> *aProperty;47- (ClassA<ProtocolY> *)aMethod;48- (ClassA<ProtocolY> *)anotherMethod;49@end50 51@implementation OtherClass52- (ClassA<ProtocolY> *)aMethod {53    // This does not work, even though ClassB subclasses from A and conforms to Y54    // because the property type explicitly adds ProtocolX conformance55    // even though ClassB already conforms to ProtocolX56    return self.aProperty;57}58- (ClassA<ProtocolY> *)anotherMethod {59    // This works, even though all it is doing is removing an explicit60    // protocol conformance that ClassB already conforms to61    return (ClassB *)self.aProperty;62}63@end64