OSDN Git Service

* 30_threads/thread/native_handle/typesizes.cc: Do not run on cygwin.
[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 /* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
6 /* { dg-additional-sources "../objc-obj-c++-shared/nsconstantstring-class-impl.mm" } */
7
8 #include <stdarg.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 #ifndef __NEXT_RUNTIME__
13 #include <objc/NXConstStr.h>
14 #else
15 #include "../objc-obj-c++-shared/nsconstantstring-class.h"
16 #endif
17
18 #include "../objc-obj-c++-shared/TestsuiteObject.m"
19 #include "../objc-obj-c++-shared/runtime.h"
20
21 #define CHECK_IF(expr) if(!(expr)) abort()
22
23 template <class ARR, class TYPE> class TestT
24 {
25 public:
26   TYPE k;
27   int abc(ARR *array) {
28     return [array count] * k;
29   }
30   TestT(TYPE _k): k(_k) { }
31 };
32
33 template <class TYPE>
34 const char *getDesc(void) {
35   return [TYPE name];
36 }
37
38 @class Array;
39
40 template <class TYPE>
41 int abc(TYPE *xyz, Array *array) {
42   return [xyz count] + [array count];
43 }
44
45 @interface Array: TestsuiteObject {
46   id *arr;
47   int count;
48 }
49 + (id)arrayWithObjects:(id)first, ... ;
50 - (int)count;
51 @end
52
53 @implementation Array
54 + (id)arrayWithObjects:(id)first, ... {
55   Array *a = [Array new];
56   a->count = 0;
57   a->arr = (id *) calloc(8, sizeof(id));
58
59   va_list args;
60   va_start (args, first);
61   
62   a->arr[a->count++] = first;
63
64   for (id el; el = va_arg(args, id); a->count++)
65     a->arr[a->count] = el;
66
67   return a;
68 }
69 - (int)count {
70   return count;
71 }
72 @end
73
74 int main(void) {
75   CHECK_IF(!strcmp ([@"TestsuiteObject" cString], getDesc<TestsuiteObject>()));
76   CHECK_IF(!strcmp ([@"Array" cString], getDesc<Array>()));
77
78   Array* a1 = [Array arrayWithObjects:@"One", @"Two", @"Three", nil];
79   Array* a2 = [Array arrayWithObjects:@"Four", @"Five", nil];
80
81   TestT<Array, int> t(7);
82   CHECK_IF(t.abc(a1) + t.abc(a2) == 35);
83   CHECK_IF(abc(a1, a2) * t.k == 35);
84   return 0;
85 }