OSDN Git Service

2010-03-25 Iain Sandoe <iain.sandoe@sandoe-acoustics.co.uk>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / obj-c++.dg / template-4.mm
1 /* Author:  Ziemowit Laski <zlaski@apple.com>.  */
2
3 /* { dg-do run } */
4 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 #include "../objc-obj-c++-shared/Object1.h"
6 #include "../objc-obj-c++-shared/next-mapping.h"
7 #include <stdarg.h>
8 #include <stdlib.h>
9
10 #ifndef __NEXT_RUNTIME__
11 #include <objc/NXConstStr.h>
12 #endif
13
14 #define CHECK_IF(expr) if(!(expr)) abort()
15
16 template <class ARR, class TYPE> class TestT
17 {
18 public:
19   TYPE k;
20   int abc(ARR *array) {
21     return [array count] * k;
22   }
23   TestT(TYPE _k): k(_k) { }
24 };
25
26 template <class TYPE>
27 const char *getDesc(void) {
28   return [TYPE name];
29 }
30
31 @class Array;
32
33 template <class TYPE>
34 int abc(TYPE *xyz, Array *array) {
35   return [xyz count] + [array count];
36 }
37
38 @interface Array: Object {
39   id *arr;
40   int count;
41 }
42 + (id)arrayWithObjects:(id)first, ... ;
43 - (int)count;
44 @end
45
46 @implementation Array
47 + (id)arrayWithObjects:(id)first, ... {
48   Array *a = [Array new];
49   a->count = 0;
50   a->arr = (id *) calloc(8, sizeof(id));
51
52   va_list args;
53   va_start (args, first);
54   
55   a->arr[a->count++] = first;
56
57   for (id el; el = va_arg(args, id); a->count++)
58     a->arr[a->count] = el;
59
60   return a;
61 }
62 - (int)count {
63   return count;
64 }
65 @end
66
67 int main(void) {
68   CHECK_IF(!strcmp ([@"Object" cString], getDesc<Object>()));
69   CHECK_IF(!strcmp ([@"Array" cString], getDesc<Array>()));
70
71   Array* a1 = [Array arrayWithObjects:@"One", @"Two", @"Three", nil];
72   Array* a2 = [Array arrayWithObjects:@"Four", @"Five", nil];
73
74   TestT<Array, int> t(7);
75   CHECK_IF(t.abc(a1) + t.abc(a2) == 35);
76   CHECK_IF(abc(a1, a2) * t.k == 35);
77   return 0;
78 }
79 #include "../objc-obj-c++-shared/Object1-implementation.h"