aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/obj-c++.dg/lookup-2.mm
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/obj-c++.dg/lookup-2.mm')
-rw-r--r--gcc/testsuite/obj-c++.dg/lookup-2.mm56
1 files changed, 56 insertions, 0 deletions
diff --git a/gcc/testsuite/obj-c++.dg/lookup-2.mm b/gcc/testsuite/obj-c++.dg/lookup-2.mm
new file mode 100644
index 00000000000..f694ec9301c
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/lookup-2.mm
@@ -0,0 +1,56 @@
+/* { dg-do run } */
+
+#include <objc/Object.h>
+#include <stdlib.h>
+
+class MyWidget {
+ public:
+ int a;
+ MyWidget(void) { a = 17; }
+};
+
+MyWidget gWidget;
+
+@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;
+}