doc: Remove i?86-*-linux* installation note from 2003
[official-gcc.git] / gcc / testsuite / obj-c++.dg / template-4.mm
blob02795e76e2877e991124e88e0eea9a49dcd82d1a
1 /* Author:  Ziemowit Laski <zlaski@apple.com>.  */
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 // { dg-additional-options "-Wno-objc-root-class" }
9 #include <stdarg.h>
10 #include <stdlib.h>
11 #include <string.h>
13 #ifndef __NEXT_RUNTIME__
14 #include <objc/NXConstStr.h>
15 #else
16 #include "../objc-obj-c++-shared/nsconstantstring-class.h"
17 #endif
19 #include "../objc-obj-c++-shared/TestsuiteObject.m"
20 #include "../objc-obj-c++-shared/runtime.h"
22 #define CHECK_IF(expr) if(!(expr)) abort()
24 template <class ARR, class TYPE> class TestT
26 public:
27   TYPE k;
28   int abc(ARR *array) {
29     return [array count] * k;
30   }
31   TestT(TYPE _k): k(_k) { }
34 template <class TYPE>
35 const char *getDesc(void) {
36   return [TYPE name];
39 @class Array;
41 template <class TYPE>
42 int abc(TYPE *xyz, Array *array) {
43   return [xyz count] + [array count];
46 @interface Array: TestsuiteObject {
47   id *arr;
48   int count;
50 + (id)arrayWithObjects:(id)first, ... ;
51 - (int)count;
52 @end
54 @implementation Array
55 + (id)arrayWithObjects:(id)first, ... {
56   Array *a = [Array new];
57   a->count = 0;
58   a->arr = (id *) calloc(8, sizeof(id));
60   va_list args;
61   va_start (args, first);
62   
63   a->arr[a->count++] = first;
65   for (id el; el = va_arg(args, id); a->count++)
66     a->arr[a->count] = el;
68   return a;
70 - (int)count {
71   return count;
73 @end
75 int main(void) {
76   CHECK_IF(!strcmp ([@"TestsuiteObject" cString], getDesc<TestsuiteObject>()));
77   CHECK_IF(!strcmp ([@"Array" cString], getDesc<Array>()));
79   Array* a1 = [Array arrayWithObjects:@"One", @"Two", @"Three", nil];
80   Array* a2 = [Array arrayWithObjects:@"Four", @"Five", nil];
82   TestT<Array, int> t(7);
83   CHECK_IF(t.abc(a1) + t.abc(a2) == 35);
84   CHECK_IF(abc(a1, a2) * t.k == 35);
85   return 0;