OSDN Git Service

2010-03-25 Iain Sandoe <iain.sandoe@sandoe-acoustics.co.uk>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / func-ptr-1.m
1 /* Test for handling of function pointer ivars */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
4
5 #include "../objc-obj-c++-shared/Object1.h"
6
7 extern int strcmp(const char *, const char *);
8 extern void abort(void);
9 #define CHECK_IF(expr) if(!(expr)) abort()
10
11 typedef float (*floatfunc)(float, float);
12
13 @interface MyObject : Object
14 {
15 @public
16   int (*ivar)(int, int, int);
17   floatfunc ffunc;
18 }
19 - init;
20 @end
21
22 int foo(int a, int b, int c) {
23   return a + b + c;
24 }
25
26 float bar(float a, float b) {
27   return a * b;
28 }
29
30 @implementation MyObject
31 - init {
32   [super init];
33   ivar = foo;
34   ffunc = bar;
35   return self;
36 }
37 @end
38
39 int main ()
40 {
41   MyObject *obj = [[MyObject alloc] init];
42   const char *enc = @encode(MyObject);
43
44   CHECK_IF(obj->ivar(4, 5, 6) == 15);
45   CHECK_IF(obj->ffunc(34.0, 45.0) == 34.0 * 45.0);
46   CHECK_IF(!strcmp(enc, "{MyObject=#^?^?}"));
47   return(0);
48 }
49
50 #include "../objc-obj-c++-shared/Object1-implementation.h"
51