diff options
Diffstat (limited to 'gcc/testsuite/objc.dg/lookup-1.m')
-rw-r--r-- | gcc/testsuite/objc.dg/lookup-1.m | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/gcc/testsuite/objc.dg/lookup-1.m b/gcc/testsuite/objc.dg/lookup-1.m new file mode 100644 index 00000000000..eaabcb2c049 --- /dev/null +++ b/gcc/testsuite/objc.dg/lookup-1.m @@ -0,0 +1,54 @@ +/* { dg-do run } */ + +#include <objc/Object.h> +#include <stdlib.h> + +typedef struct MyWidget { + int a; +} MyWidget; + +MyWidget gWidget = { 17 }; + +@protocol MyProto +- (MyWidget *)widget; +@end + +@interface Foo: Object +@end + +@interface Bar: Foo <MyProto> +@end + +@interface Container: Object ++ (MyWidget *)elementForView:(Foo *)view; +@end + +@implementation Foo +@end + +@implementation Bar +- (MyWidget *)widget { + return &gWidget; +} +@end + +@implementation Container ++ (MyWidget *)elementForView:(Foo *)view +{ + MyWidget *widget = nil; + if ([view conformsTo:@protocol(MyProto)]) { + widget = [(Foo <MyProto> *)view widget]; + } + return widget; +} +@end + +int main(void) { + id view = [Bar new]; + MyWidget *w = [Container elementForView: view]; + + if (!w || w->a != 17) + abort (); + + return 0; +} |