1 module foo.bar;
2
3 import core.vararg;
4 import std.stdio;
5
6 pragma(lib, "test");
7 pragma(msg, "Hello World");
8
9 static assert(true, "message");
10
11 alias double mydbl;
12
testmain()13 int testmain()
14 in
15 {
16 assert(1+(2+3) == -(1 - 2*3));
17 }
out(result)18 out (result)
19 {
20 assert(result == 0);
21 }
22 body
23 {
24 float f = float.infinity;
25 int i = cast(int) f;
26 writeln((i,1),2);
27 writeln(cast(int)float.max);
28 assert(i == cast(int)float.max);
29 assert(i == 0x80000000);
30 return 0;
31 }
32
33 struct S { int m, n; }
34
Foo(T,int V)35 template Foo(T, int V)
36 {
37 void foo(...)
38 {
39 static if (is(Object _ : X!TL, alias X, TL...)) {} // Bugzilla 10044
40
41 auto x = __traits(hasMember, Object, "noMember");
42 auto y = is(Object : X!TL, alias X, TL...);
43 assert(!x && !y, "message");
44
45 S s = { 1,2 };
46 auto a = [1, 2, 3];
47 auto aa = [1:1, 2:2, 3:3];
48
49 int n,m;
50 }
51
52 int bar(double d, int x)
53 {
54 if (d)
55 { d++;
56 }
57 else
58 d--;
59
60 asm
61 { naked ;
62 mov EAX, 3;
63 }
64
65 for (;;)
66 {
67 d = d + 1;
68 }
69
70 for (int i = 0; i < 10; i++)
71 {
72 d = i ? d + 1 : 5;
73 }
74
75 char[] s;
76 foreach (char c; s)
77 {
78 d *= 2;
79 if (d)
80 break;
81 else
82 continue;
83 }
84
85 switch (V)
86 {
87 case 1:
88 case 2: break;
89 case 3: goto case 1;
90 case 4: goto default;
91 default:
92 d /= 8;
93 break;
94 }
95
96 enum Label { A, B, C }
97 void fswitch(Label l)
98 {
99 final switch (l)
100 {
101 case A: break;
102 case B: break;
103 case C: break;
104 }
105 }
106
107 loop:
108 while (x)
109 {
110 x--;
111 if (x)
112 break loop;
113 else
114 continue loop;
115 }
116
117 do
118 {
119 x++;
120 } while (x < 10);
121
122 try
123 {
124 bar(1, 2);
125 }
126 catch (Object o)
127 {
128 x++;
129 }
130 finally
131 {
132 x--;
133 }
134
135 try
136 bar(1, 2);
137 catch(Object o)
138 x++;
139 finally
140 x--;
141
142 Object o;
143 synchronized (o)
144 {
145 x = ~x;
146 }
147
148 synchronized
149 {
150 x = x < 3;
151 }
152
153 with (o)
154 {
155 toString();
156 }
157 }
158 }
159
this()160 static this()
161 {
162 }
163
~this()164 static ~this()
165 {
166 }
167
this()168 pure nothrow @safe @nogc static this() {}
~this()169 pure nothrow @safe @nogc static ~this() {}
this()170 static this() pure nothrow @safe @nogc {}
~this()171 static ~this() pure nothrow @safe @nogc {}
172
this()173 pure nothrow @safe @nogc shared static this() {}
~this()174 pure nothrow @safe @nogc shared static ~this() {}
this()175 shared static this() pure nothrow @safe @nogc {}
~this()176 shared static ~this() pure nothrow @safe @nogc {}
177
178 interface iFoo{}
179 class xFoo: iFoo{}
180
181 interface iFoo2{}
182 class xFoo2: iFoo, iFoo2{}
183
184 class Foo3
185 {
this(int a,...)186 this(int a, ...){}
this(int * a)187 this(int* a){}
188 }
189
190 alias int myint;
191
192 static notquit = 1;
193
194 class Test
195 {
a()196 void a() {}
b()197 void b() {}
c()198 void c() {}
d()199 void d() {}
e()200 void e() {}
f()201 void f() {}
g()202 void g() {}
h()203 void h() {}
i()204 void i() {}
j()205 void j() {}
k()206 void k() {}
l()207 void l() {}
m()208 void m() {}
n()209 void n() {}
o()210 void o() {}
p()211 void p() {}
q()212 void q() {}
r()213 void r() {}
s()214 void s() {}
t()215 void t() {}
u()216 void u() {}
v()217 void v() {}
w()218 void w() {}
x()219 void x() {}
y()220 void y() {}
z()221 void z() {}
222
aa()223 void aa() {}
bb()224 void bb() {}
cc()225 void cc() {}
dd()226 void dd() {}
ee()227 void ee() {} // Try adding or removing some functions here to see the effect.
228
A(T)229 template A(T) { }
230
231 alias A!(uint) getHUint;
232 alias A!(int) getHInt;
233 alias A!(float) getHFloat;
234 alias A!(ulong) getHUlong;
235 alias A!(long) getHLong;
236 alias A!(double) getHDouble;
237 alias A!(byte) getHByte;
238 alias A!(ubyte) getHUbyte;
239 alias A!(short) getHShort;
240 alias A!(ushort) getHUShort;
241 alias A!(real) getHReal;
242
243 alias void F();
244
245 pure nothrow @safe @nogc unittest {}
246 pure nothrow @safe @nogc invariant {}
247
new(size_t sz)248 pure nothrow @safe @nogc new (size_t sz) { return null; }
delete(void * p)249 pure nothrow @safe @nogc delete (void* p) { }
250 }
251
templ(T)252 template templ( T )
253 {
254 void templ( T val )
255 {
256 pragma( msg, "Invalid destination type." );
257 }
258 }
259
260 static char[] charArray = [ '\"', '\'' ];
261
262 class Point
263 {
264 auto x = 10;
265 uint y = 20;
266 }
267
Foo2(bool bar)268 template Foo2(bool bar)
269 {
270 void test()
271 {
272 static if(bar)
273 {
274 int i;
275 }
276 else
277 {
278 }
279 static if(!bar)
280 {
281 }
282 else
283 {
284 }
285 }
286 }
287
288
Foo4()289 template Foo4()
290 {
291 void bar()
292 {
293 }
294 }
295
Foo4x(T...)296 template Foo4x( T... ) {}
297
298 class Baz4
299 {
300 mixin Foo4 foo;
301 mixin Foo4x!(int, "str") foox;
302
303 alias foo.bar baz;
304 }
305
test(T)306 int test(T)(T t)
307 {
308 if (auto o = cast(Object)t) return 1;
309 return 0;
310 }
311
312 enum x6 = 1;
313
foo6(int a,int b,int c,int d)314 bool foo6(int a, int b, int c, int d)
315 {
316 return (a < b) != (c < d);
317 }
318
foo7(int x)319 auto foo7(int x)
320 {
321 return 5;
322 }
323
324 class D8{}
func8()325 void func8()
326 {
327 scope a= new D8();
328 }
329
330 T func9(T)() if (true)
331 {
332 T i;
333 scope(exit) i= 1;
334 scope(success) i = 2;
335 scope(failure) i = 3;
336 return i;
337 }
338
V10(T)339 template V10(T)
340 {
341 void func()
342 {
343 for(int i,j=4; i<3;i++)
344 {
345 }
346 }
347 }
348
foo11(int function ()fn)349 int foo11(int function() fn)
350 {
351 return fn();
352 }
353
bar11(T)354 int bar11(T)()
355 {
356 return foo11(function int (){ return 0; });
357 }
358
359
360 struct S6360
361 {
weeks1S6360362 @property long weeks1() const pure nothrow { return 0; }
363
weeks2S6360364 @property const pure nothrow long weeks2() { return 0; }
365 }
366
367
368 struct S12
369 {
370 /// postfix storage class and constructor
this(int n)371 this(int n) nothrow{}
372
373 /// prefix storage class (==StorageClassDeclaration) and constructor
this(string s)374 nothrow this(string s){}
375 }
376
377 /// dummy
378 struct T12
379 {
380 /// postfix storage class and template constructor
thisT12381 this()(int args) immutable { }
382
383 /// prefix storage class (==StorageClassDeclaration) and template constructor
thisT12384 immutable this(A...)(A args){ }
385 }
386
387
388 // 6591
389 import std.stdio : writeln, F = File;
390
foo6591()391 void foo6591()()
392 {
393 import std.stdio : writeln, F = File;
394 }
395
396
397 // 8081
version(unittest)398 version(unittest) {
399 pure nothrow unittest {}
400 pure nothrow unittest {}
401
402 public unittest {}
403 extern(C) unittest {}
404 align unittest {}
405 }
406
407
408 // 10334
409
410 template Foo10334(T) if (Bar10334!()) {} ///
411 template Foo10334(T) if (Bar10334!100) {} ///
412 template Foo10334(T) if (Bar10334!3.14) {} ///
413 template Foo10334(T) if (Bar10334!"str") {} ///
414 template Foo10334(T) if (Bar10334!1.4i) {} ///
415 template Foo10334(T) if (Bar10334!null) {} ///
416 template Foo10334(T) if (Bar10334!true) {} ///
417 template Foo10334(T) if (Bar10334!false) {} ///
418 template Foo10334(T) if (Bar10334!'A') {} ///
419 template Foo10334(T) if (Bar10334!int) {} ///
420 template Foo10334(T) if (Bar10334!string) {} ///
421 template Foo10334(T) if (Bar10334!wstring) {} ///
422 template Foo10334(T) if (Bar10334!dstring) {} ///
423 template Foo10334(T) if (Bar10334!this) {} ///
424 template Foo10334(T) if (Bar10334!([1,2,3])) {} ///
425 template Foo10334(T) if (Bar10334!(Baz10334!())) {} ///
426 template Foo10334(T) if (Bar10334!(Baz10334!T)) {} ///
427 template Foo10334(T) if (Bar10334!(Baz10334!100)) {} ///
428 template Foo10334(T) if (Bar10334!(.foo)) {} ///
429 template Foo10334(T) if (Bar10334!(const int)) {} ///
430 template Foo10334(T) if (Bar10334!(shared T)) {} ///
431
Test10334(T...)432 template Test10334(T...) {} ///
433 mixin Test10334!int a; ///
434 mixin Test10334!(int,long) b; ///
435 mixin Test10334!"str" c; ///
436
437 // 12266
clamp12266a(T1,T2,T3)438 auto clamp12266a(T1, T2, T3)(T1 x, T2 min_val, T3 max_val)
439 {
440 return 0;
441 }
clamp12266b(T1,T2,T3)442 pure clamp12266b(T1, T2, T3)(T1 x, T2 min_val, T3 max_val)
443 {
444 return 0;
445 }
clamp12266c(T1,T2,T3)446 @disable pure clamp12266c(T1, T2, T3)(T1 x, T2 min_val, T3 max_val)
447 {
448 return 0;
449 }
450
451 // 13832
452 alias Dg13832 = ref int delegate();
453
454 // 16590
455 class TestClass {
456 int aa;
457 int b1, b2;
this(int b1,int b2)458 this(int b1, int b2)
459 {
460 this.b1 = b1;
461 this.b2 = b2;
462 }
463
foo()464 ref foo() {
465 return aa;
466 }
467
468 ref retFunc() return {
469 return aa;
470 }
471
472 ~this() @trusted @disable @nogc {
473 }
474 }
475
476 class FooA {
477 protected void method42() {
478
479 }
480
481 ~this() @safe {
482 }
483
484 }
485
486
487 class Bar : FooA {
488 override void method42() {
489
490 }
491 }
492
493 double foo() @trusted {
494 int a = 5;
495 return a;
496 }
497
498 struct Foo1(size_t Size = 42 / magic()) {
499
500 }
501
502
503 size_t magic() {
504 return 42;
505 }
506
507 class Foo2A {
508
509 immutable(FooA) Dummy = new immutable(FooA);
510 private immutable pure nothrow @nogc @safe this() {
511
512 }
513
514 }
515
516 // bugzilla 15676
517 struct Foo3A(T)
518 {
519 @disable this(this);
520 @disable this();
521 }
522