2014-07-11 Edward Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / gcc / testsuite / obj-c++.dg / template-4.mm
blob5301df5c0e0a6ee89913ba4b2983739f824dc103
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" } */
8 #include <stdarg.h>
9 #include <stdlib.h>
10 #include <string.h>
12 #ifndef __NEXT_RUNTIME__
13 #include <objc/NXConstStr.h>
14 #else
15 #include "../objc-obj-c++-shared/nsconstantstring-class.h"
16 #endif
18 #include "../objc-obj-c++-shared/TestsuiteObject.m"
19 #include "../objc-obj-c++-shared/runtime.h"
21 #define CHECK_IF(expr) if(!(expr)) abort()
23 template <class ARR, class TYPE> class TestT
25 public:
26   TYPE k;
27   int abc(ARR *array) {
28     return [array count] * k;
29   }
30   TestT(TYPE _k): k(_k) { }
33 template <class TYPE>
34 const char *getDesc(void) {
35   return [TYPE name];
38 @class Array;
40 template <class TYPE>
41 int abc(TYPE *xyz, Array *array) {
42   return [xyz count] + [array count];
45 @interface Array: TestsuiteObject {
46   id *arr;
47   int count;
49 + (id)arrayWithObjects:(id)first, ... ;
50 - (int)count;
51 @end
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));
59   va_list args;
60   va_start (args, first);
61   
62   a->arr[a->count++] = first;
64   for (id el; el = va_arg(args, id); a->count++)
65     a->arr[a->count] = el;
67   return a;
69 - (int)count {
70   return count;
72 @end
74 int main(void) {
75   CHECK_IF(!strcmp ([@"TestsuiteObject" cString], getDesc<TestsuiteObject>()));
76   CHECK_IF(!strcmp ([@"Array" cString], getDesc<Array>()));
78   Array* a1 = [Array arrayWithObjects:@"One", @"Two", @"Three", nil];
79   Array* a2 = [Array arrayWithObjects:@"Four", @"Five", nil];
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;