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