Debian Codegraph @

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

raw
1 /*
2 RUN_OUTPUT:
3 ---
4 Success
5 ---
6 */
7 import core.stdc.stdio;
8
9 class A
10 {
11 immutable size_t f;
12
13 this(T)(T z)
14 {
15 f = z.sizeof;
16 }
17 }
18
19 struct AS
20 {
21 immutable size_t f;
22
23 this(T)(T z)
24 {
25 f = z.sizeof;
26 }
27 }
28
29 void test0()
30 {
31 assert((new A(2.2)).f == double.sizeof);
32 assert((new A('g')).f == char.sizeof);
33 assert((AS(17)).f == int.sizeof);
34 assert((AS(null)).f == typeof(null).sizeof);
35 }
36
37 //------------------------------------------------------------------------------
38
39 class C
40 {
41 const int x;
42 const int y;
43
44 this(T...)(T z)
45 {
46 this.tupleof = z;
47 }
48 }
49
50 struct CS
51 {
52 const int x;
53 const int y;
54
55 this(T...)(T z)
56 {
57 this.tupleof = z;
58 }
59 }
60
61 void test1()
62 {
63 auto c = new C(4, 6);
64 assert(c.x == 4);
65 assert(c.y == 6);
66
67 auto cs = CS(7, 8);
68 assert(cs.x == 7);
69 assert(cs.y == 8);
70 }
71
72 //------------------------------------------------------------------------------
73
74 // https://issues.dlang.org/show_bug.cgi?id=435.
75 class B
76 {
77 int i;
78 this(int k)
79 {
80 i = k;
81 }
82 }
83 class D : B
84 {
85 this(A...)(A args)
86 {
87 super(args);
88 }
89 }
90
91 void test2()
92 {
93 auto a = new D(4);
94 assert(a.i == 4);
95 }
96
97 //------------------------------------------------------------------------------
98
99 // https://issues.dlang.org/show_bug.cgi?id=4905
100 class C2
101 {
102 string x;
103
104 this(T...)(in string msg, T args)
105 {
106 x = msg;
107 foreach (a; args)
108 x ~= a;
109 }
110 }
111
112 void test3()
113 {
114 auto c2 = new C2("test");
115 assert(c2.x == "test");
116
117 auto c3 = new C2("test", " variadic", " constructor");
118 assert(c3.x == "test variadic constructor");
119 }
120
121 //------------------------------------------------------------------------------
122
123 // https://issues.dlang.org/show_bug.cgi?id=4531 test case 2
124 class MyError : Exception
125 {
126 this(T...)(T msg)
127 {
128 assert(msg[0] == "Hello, " && msg[1] == 42);
129 super("Hello, 42");
130 }
131 }
132
133 void test4()
134 {
135 auto err = new MyError("Hello, ", 42);
136 assert(err.msg == "Hello, 42");
137 }
138
139 void main()
140 {
141 test0();
142 test1();
143 test2();
144 test3();
145 test4();
146 printf("Success\n");
147 }