3 extern(C) int printf(const char*, ...);
5 int testswitch(string h)
35 i = testswitch("foo");
36 printf("i = %d\n", i);
38 assert(testswitch("abc") == 4);
39 assert(testswitch("bar") == 2);
40 assert(testswitch("hello") == 3);
44 /*****************************************/
64 /*****************************************/
87 /*****************************************/
110 /*****************************************/
132 /*****************************************/
155 /*****************************************/
178 /*****************************************/
198 /*****************************************/
222 /*****************************************/
230 case 0: ++id; goto case;
231 case 7: ++id; goto case;
232 case 6: ++id; goto case;
233 case 5: ++id; goto case;
234 case 4: ++id; goto case;
235 case 3: ++id; goto case;
236 case 2: ++id; goto case;
237 case 1: ++id; goto default;
244 /*****************************************/
251 case 2: assert (false);
259 /*****************************************/
265 case "#!": printf("----Found #!\n"); break;
266 case "\xFF\xFE"c: break;
272 /*****************************************/
278 case "#!": printf("----Found #!\n"); break;
279 case "#\xFE"c: break;
285 /*****************************************/
287 void foo14(A...)(int i)
303 void bar14(A...)(int i)
311 printf("a = %d, A[%zd] = %d\n", a, j, A[j]);
321 foo14!(1,2,3,4,5)(1);
322 bar14!(1,2,3,4,5)(1);
325 /*****************************************/
352 printf("y = %d\n", y);
379 /*****************************************/
398 /*****************************************/
429 /*****************************************/
435 final switch(x){ case foo.bar: return 0; }
438 /*****************************************/
451 /*****************************************/
461 int wrongcode3139(int x)
464 case -9: .. case 2: return 3;
470 static assert(wrongcode3139(-5)==3);
472 // https://issues.dlang.org/show_bug.cgi?id=3139
473 static assert(!is(typeof(
474 (long x) { switch(x) { case long.max: .. case -long.max:
475 default:} return 4; }(3)
479 /*****************************************/
483 static void test7358a()
485 enum X { A = 1, B = 2 }
505 /*****************************************/
506 // https://issues.dlang.org/show_bug.cgi?id=9263
513 final switch (f) with(Foo)
520 /*****************************************/
526 // case 1: return 11;
558 // printf("j = %d\n", j);
560 for (int i = 2; i < 21; i++)
563 //printf("j = %d\n", j);
568 /*****************************************/
574 case 1: return i + 1;
575 case 10: return i + 2;
576 case 20: return i + 3;
577 case 50: return i + 4;
578 case 1000: return i + 5;
585 assert(bar22(1) == 2);
586 assert(bar22(10) == 12);
587 assert(bar22(20) == 23);
588 assert(bar22(50) == 54);
589 assert(bar22(1000) == 1005);
590 assert(bar22(0) == 28);
591 assert(bar22(5) == 28);
592 assert(bar22(15) == 28);
593 assert(bar22(25) == 28);
594 assert(bar22(58) == 28);
595 assert(bar22(2000) == 28);
598 /*****************************************/
604 case 1: return i + 1;
605 case 0x10_0000_0000L: return i + 2;
606 case 0x20_0070_0000L: return i + 3;
607 case 0x50_0000_0000L: return i + 4;
608 case 0x1000_0000_8000L: return i + 5;
615 assert(bar23(1) == 2);
616 assert(bar23(0x10_0000_0000L) == 0x10_0000_0000L + 2);
617 assert(bar23(0x20_0070_0000L) == 0x20_0070_0000L + 3);
618 assert(bar23(0x50_0000_0000L) == 0x50_0000_0000L + 4);
619 assert(bar23(0x1000_0000_8000L) == 0x1000_0000_8000L + 5);
620 assert(bar23(0) == 28);
621 assert(bar23(58) == 28);
622 assert(bar23(0x10_0000_0000L+1) == 28);
623 assert(bar23(0x20_0070_0000L+5) == 28);
624 assert(bar23(0x50_0000_0000L+25) == 28);
625 assert(bar23(0x1000_0000_8000L+1) == 28);
628 /*****************************************/
629 // https://issues.dlang.org/show_bug.cgi?id=14352
631 int transmogrify14352(int input)
662 assert(transmogrify14352(0) == 10);
665 /*****************************************/
666 // https://issues.dlang.org/show_bug.cgi?id=14587
667 // DMD 2.067.1 generating crashing binary on OSX
674 void foo14587(Card card) {
676 case 4: case 5: case 6: case 11:
683 auto card = Card(11, 1);
687 /*****************************************/
688 // https://issues.dlang.org/show_bug.cgi?id=15396
689 // static immutable not recognized as constant within switch statement
693 static immutable Foo = "Foobar";
694 static const Bar = "BarFoo";
696 foreach (var; [ "Foobar", "BarFoo" ])
705 assert(0, "test15396 failed");
710 /*****************************************/
711 // https://issues.dlang.org/show_bug.cgi?id=15538
734 assert(f15538(s) == 10); /* fails */
737 /*****************************************/