Debian Codegraph @

gcc/testsuite/gdc.test/runnable/ifti.d

raw
1 extern (C) int printf(const scope char*, ...);
2
3 struct S {
4 int x = 3;
5 void fun(T)(T x) { printf("S.fun(%s)(%d)\n", T.stringof.ptr, x); this.x += x; }
6 }
7
8 class Tst(TST, int v = 2) {
9 int x = 3;
10 int z = 4;
11
12 final private void proc(int x) { printf("proc(%d) -> %d\n", x, this.x); }
13 void fun(T)(T x) { printf("fun(%s)(%d) -> %d\n", T.stringof.ptr, x, this.x);}
14 void fun()() { printf("fun()() -> %d\n", this.x); }
15 void fun2()() { printf("fun2\n"); }
16
17 class Inner {
18 int y = 99;
19 Tst outer;
20 void f3() { z = 55; }
21 // Make sure the correct this-ptr is used
22 void f1() { printf("Inner.f1\n"); proc(-11); outer.proc(-11); }
23 void f2() { printf("Inner.f2\n"); fun(-17); outer.fun(-17); }
24 }
25 Inner inner;
26
27 this() {
28 inner = new Inner;
29 inner.outer = this;
30 }
31
32 void callInnerf1() { printf("callInnerf1\n"); inner.f1(); }
33 void callInnerf2() { printf("callInnerf2\n"); inner.f2(); }
34
35
36 //
37 void opBinary(string op : "+", T)(T x) { this.x += x; printf("opAdd(%d)\n", x); }
38 void opUnary(string op : "+")() { printf("opPos()\n"); }
39 //void opPos() { printf("xxx"); }
40 void opIndex(T)(T x) { printf("opIndex[%d]\n",x); }
41
42 void opIndex(A,B,C)(A a, B b, C c) {
43 printf("opIndex[(%s) %d, (%s) %d, (%s) %d]\n", A.stringof.ptr, a,
44 B.stringof.ptr,b,C.stringof.ptr,c);
45 }
46
47 static if (v > 1) {
48 void opCall(A = int, B = float)(A a = 1, B b = 8.2) { printf("opCall(%d, %d)\n",a,b); this.x++; }
49 }
50 void opSlice(A,B)(A a, B b) { printf("opSlice(%d, %d)\n",a,b); }
51 void opSlice()() { printf("opSlice()\n"); }
52
53 void opIndexAssign(A,B)(A a, B b) {
54 printf("opIndexAssign((%s) %d, (%s) %d)\n", A.stringof.ptr, a, B.stringof.ptr, b);
55 }
56
57 void opSliceAssign(A,B,C)(A a, B b, C c) {
58 printf("opSliceAssign(%.s, %d, %d)\n", a.length, a.ptr, b, c);
59 }
60
61 bool opEquals(A)(A x) { printf("opEquals((%s))\n", A.stringof.ptr); return true; }
62
63 int opApply(T)(int delegate(ref T)dg) {
64 for (int i = 0; i < 5; i++) {
65 T d = cast(T)(i+0.1);
66 if (auto result = dg(d))
67 return result;
68 }
69 return 0;
70 }
71 }
72
73 class Y : Tst!(float) {}
74
75 // https://issues.dlang.org/show_bug.cgi?id=24731
76 void test24731()
77 {
78 static int solve(size_t N)(ref double[N+1][N])
79 {
80 return N;
81 }
82
83 double[3][2] m;
84 assert(solve(m) == 2);
85 assert(solve!2(m) == 2);
86 }
87
88
89 void main() {
90 Tst!(int) t = new Tst!(int);
91 Y u = new Y;
92 S s;
93 t.x = 7;
94 t.proc(5);
95 t.fun(5);
96 t.fun();
97 t.callInnerf1();
98 t.callInnerf2();
99 u.fun(5);
100 u.fun();
101 u.callInnerf1();
102 u.callInnerf2();
103 s.fun(5);
104 t.fun2();
105
106 +t;
107 t+5;
108 t[55];
109 t[1,2,3.0];
110 u[1,2,3.0];
111 t(1,2.5);
112 t(2);
113 t();
114 t[];
115 t[1..2];
116 u[1..2.5];
117 t == t;
118 auto b = t != t; // without assignment -> "! has no effect in expression"
119 t == u;
120 u == t;
121 u == u;
122 b = u != u;
123 foreach(int i;t) {
124 printf("%d\n", i);
125 }
126 foreach(double i;t) {
127 printf("%g\n", i);
128 }
129
130 test24731();
131 }