Debian Codegraph @

gcc/testsuite/obj-c++.dg/template-4.mm

raw
1 /* Author: Ziemowit Laski <[email protected]>. */
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 // { dg-additional-options "-Wno-objc-root-class" }
8
9 #include <stdarg.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #ifndef __NEXT_RUNTIME__
14 #include <objc/NXConstStr.h>
15 #else
16 #include "../objc-obj-c++-shared/nsconstantstring-class.h"
17 #endif
18
19 #include "../objc-obj-c++-shared/TestsuiteObject.m"
20 #include "../objc-obj-c++-shared/runtime.h"
21
22 #define CHECK_IF(expr) if(!(expr)) abort()
23
24 template <class ARR, class TYPE> class TestT
25 {
26 public:
27 TYPE k;
28 int abc(ARR *array) {
29 return [array count] * k;
30 }
31 TestT(TYPE _k): k(_k) { }
32 };
33
34 template <class TYPE>
35 const char *getDesc(void) {
36 return [TYPE name];
37 }
38
39 @class Array;
40
41 template <class TYPE>
42 int abc(TYPE *xyz, Array *array) {
43 return [xyz count] + [array count];
44 }
45
46 @interface Array: TestsuiteObject {
47 id *arr;
48 int count;
49 }
50 + (id)arrayWithObjects:(id)first, ... ;
51 - (int)count;
52 @end
53
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));
59
60 va_list args;
61 va_start (args, first);
62
63 a->arr[a->count++] = first;
64
65 for (id el; el = va_arg(args, id); a->count++)
66 a->arr[a->count] = el;
67
68 return a;
69 }
70 - (int)count {
71 return count;
72 }
73 @end
74
75 int main(void) {
76 CHECK_IF(!strcmp ([@"TestsuiteObject" cString], getDesc<TestsuiteObject>()));
77 CHECK_IF(!strcmp ([@"Array" cString], getDesc<Array>()));
78
79 Array* a1 = [Array arrayWithObjects:@"One", @"Two", @"Three", nil];
80 Array* a2 = [Array arrayWithObjects:@"Four", @"Five", nil];
81
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;
86 }