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