| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ |
| 3 |
|
| 4 |
#include <stdlib.h> |
| 5 |
#include "../objc-obj-c++-shared/TestsuiteObject.m" |
| 6 |
|
| 7 |
typedef struct MyWidget { |
| 8 |
int a; |
| 9 |
} MyWidget; |
| 10 |
|
| 11 |
MyWidget gWidget = { 17 }; |
| 12 |
|
| 13 |
@protocol MyProto |
| 14 |
- (MyWidget *)widget; |
| 15 |
@end |
| 16 |
|
| 17 |
@interface Foo: TestsuiteObject |
| 18 |
@end |
| 19 |
|
| 20 |
@interface Bar: Foo <MyProto> |
| 21 |
@end |
| 22 |
|
| 23 |
@interface Container: TestsuiteObject |
| 24 |
+ (MyWidget *)elementForView:(Foo *)view; |
| 25 |
@end |
| 26 |
|
| 27 |
@implementation Foo |
| 28 |
@end |
| 29 |
|
| 30 |
@implementation Bar |
| 31 |
- (MyWidget *)widget { |
| 32 |
return &gWidget; |
| 33 |
} |
| 34 |
@end |
| 35 |
|
| 36 |
@implementation Container |
| 37 |
+ (MyWidget *)elementForView:(Foo *)view |
| 38 |
{ |
| 39 |
MyWidget *widget = (MyWidget *) nil; |
| 40 |
if (class_conformsToProtocol (object_getClass (view), |
| 41 |
@protocol(MyProto))) { |
| 42 |
widget = [(Foo <MyProto> *)view widget]; |
| 43 |
} |
| 44 |
return widget; |
| 45 |
} |
| 46 |
@end |
| 47 |
|
| 48 |
int main(void) { |
| 49 |
id view = [Bar new]; |
| 50 |
MyWidget *w = [Container elementForView: view]; |
| 51 |
|
| 52 |
if (!w || w->a != 17) |
| 53 |
abort (); |
| 54 |
|
| 55 |
return 0; |
| 56 |
} |