1// RUN: %clang_cc1 -x objective-c -Wno-objc-root-class -fms-extensions -rewrite-objc %s -o %t-rw.cpp 2// RUN: FileCheck --input-file=%t-rw.cpp %s 3 4typedef struct MyWidget { 5 int a; 6} MyWidget; 7 8MyWidget gWidget = { 17 }; 9 10@protocol MyProto 11- (MyWidget *)widget; 12@end 13 14@interface Foo 15@end 16 17@interface Bar: Foo <MyProto> 18@end 19 20@interface Container 21+ (MyWidget *)elementForView:(Foo *)view; 22@end 23 24@implementation Foo 25@end 26 27@implementation Bar 28- (MyWidget *)widget { 29 return &gWidget; 30} 31@end 32 33@implementation Container 34+ (MyWidget *)elementForView:(Foo *)view 35{ 36 MyWidget *widget = (void*)0; 37 if (@protocol(MyProto)) { 38 widget = [(id <MyProto>)view widget]; 39 } 40 return widget; 41} 42@end 43 44int main(void) { 45 id view; 46 MyWidget *w = [Container elementForView: view]; 47 48 return 0; 49} 50 51@class NSObject; 52 53@interface NSProtocolChecker 54+ (id)protocolCheckerWithTarget:(NSObject *)anObject protocol:(Protocol *)aProtocol; 55@end 56 57@protocol NSConnectionVersionedProtocol 58@end 59 60 61@interface NSConnection @end 62 63@implementation NSConnection 64- (void) Meth { 65 [NSProtocolChecker protocolCheckerWithTarget:0 protocol:@protocol(NSConnectionVersionedProtocol)]; 66} 67@end 68 69// CHECK: static struct _protocol_t *_OBJC_PROTOCOL_REFERENCE_$_NSConnectionVersionedProtocol = &_OBJC_PROTOCOL_NSConnectionVersionedProtocol 70// CHECK: sel_registerName("protocolCheckerWithTarget:protocol:"), (NSObject *)0, (Protocol *)_OBJC_PROTOCOL_REFERENCE_$_NSConnectionVersionedProtocol 71