1 extern(C) int printf(const char*, ...);
2
Seq(T...)3 template Seq(T...) { alias T Seq; }
4
5 /***************************************************/
6 // 3133
7
test3133()8 void test3133()
9 {
10 short[2] x = [1, 2];
11 auto y = cast(int[1])x; // no error
12 }
13
14 /***************************************************/
15 // 7504
16
test7504()17 void test7504() pure nothrow @safe
18 {
19 auto n = null;
20 char[] k = n;
21 assert(k.ptr == null);
22 assert(k.length == 0);
23
24 double[] l;
25 l = n;
26 assert(l.ptr == null);
27 assert(l.length == 0);
28
29 immutable(int[]) m = n;
30 assert(m.ptr == null);
31 assert(m.length == 0);
32
33 const(float)[] o;
34 o = n;
35 assert(o.ptr == null);
36 assert(o.length == 0);
37
38 auto c = create7504(null, null);
39 assert(c.k.ptr == null);
40 assert(c.k.length == 0);
41 assert(c.l.ptr == null);
42 assert(c.l.length == 0);
43 }
44
45 class C7504
46 {
47 int[] k;
48 string l;
49 }
50
create7504(T...)51 C7504 create7504(T...)(T input)
52 {
53 auto obj = new C7504;
54 obj.tupleof = input;
55 return obj;
56 }
57
58 /***************************************************/
59 // 8119
60
61 struct S8119;
62
test8119()63 void test8119()
64 {
65 void* v;
66 auto sp1 = cast(S8119*)v;
67
68 int* i;
69 auto sp2 = cast(S8119*)i;
70
71 S8119* s;
72 auto ip = cast(int*)s;
73 }
74
75 /***************************************************/
76 // 8645
77
TypeTuple8645(TL...)78 template TypeTuple8645(TL...)
79 {
80 alias TL TypeTuple8645;
81 }
82
test8645()83 void test8645()
84 {
85 alias TypeTuple8645!(int) Foo;
86 int bar;
87 static assert(!is(typeof( cast(Foo)bar )));
88 }
89
90 /***************************************************/
91 // 10497
92
93 struct S10497;
94
test10497(S10497 ** s)95 void test10497(S10497** s)
96 {
97 void* ptr;
98 *s = cast(S10497*)ptr;
99 }
100
101 /***************************************************/
102 // 10793
103
104 struct RealFoo10793
105 {
106 int i;
107 }
108
109 struct Foo10793;
110
test10793()111 void test10793()
112 {
113 auto rf = RealFoo10793(10);
114 void* prf = cast(void*)&rf;
115 Foo10793* f = cast(Foo10793*)prf;
116 }
117
118 /***************************************************/
119 // 10834
120
test10834()121 void test10834()
122 {
123 struct S { int i; }
124 S s;
125 cast(void)s;
126
127 class C { int i; }
128 C c;
129 cast(void)c;
130
131 enum E { a, b }
132 E e;
133 cast(void)e;
134
135 int[] ia;
136 cast(void)ia;
137 }
138
139 /***************************************************/
140 // 10842
141
Test10842(F,T)142 template Test10842(F, T)
143 {
144 bool res;
145 F from()
146 {
147 res = true;
148 return F.init;
149 }
150 T to()
151 {
152 // The cast operand had incorrectly been eliminated
153 return cast(T)from();
154 }
155 bool test()
156 {
157 res = false;
158 to();
159 return res;
160 }
161 }
162
test10842()163 void test10842()
164 {
165 foreach (From; Seq!(bool, byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real))
166 {
167 foreach (To; Seq!(ifloat, idouble, ireal))
168 {
169 if (!Test10842!(From, To).test())
170 assert(0);
171 }
172 }
173
174 foreach (From; Seq!(ifloat, idouble, ireal))
175 {
176 foreach (To; Seq!(/*bool*, */byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real))
177 {
178 if (!Test10842!(From, To).test())
179 assert(0);
180 }
181 }
182
183 if (!Test10842!(typeof(null), string).test()) // 10842
184 assert(0);
185 }
186
187 /***************************************************/
188 // 11722
189
190 class C11722
191 {
opCast(T)192 T opCast(T)() { assert(0); }
193 }
194
test11722()195 void test11722()
196 {
197 C11722 c = new C11722();
198 shared C11722 sc = cast(shared)c;
199 }
200
201 /***************************************************/
202 // 14218
203
test14218()204 void test14218()
205 {
206 foreach (To; Seq!( byte, short, int, long,
207 ubyte, ushort, uint, ulong,
208 char, wchar, dchar, bool))
209 {
210 auto x = cast(To)null;
211 assert(x == 0); // false, '0x00'
212 }
213
214 version (DigitalMars)
215 {
216 // Questionable but currently accepted by DMD (but not GDC).
217 foreach (To; Seq!( float, double, real,
218 ifloat, idouble, ireal))
219 {
220 auto x = cast(To)null;
221 assert(x == 0); // 0i
222 }
223
224 // Internal error: backend/el.c in el_long()
225 //foreach (To; Seq!(cfloat, cdouble, creal))
226 //{
227 // static assert(!__traits(compiles, { auto x = cast(To)null; }));
228 //}
229 }
230 }
231
232 /***************************************************/
233
main()234 int main()
235 {
236 test3133();
237 test7504();
238 test8119();
239 test8645();
240 test10793();
241 test10834();
242 test10842();
243 test11722();
244 test14218();
245
246 printf("Success\n");
247 return 0;
248 }
249