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