1 // REQUIRED_ARGS: -w 2 // PERMUTE_ARGS: 3 4 extern(C) int printf(const char*, ...); 5 6 /******************************************/ 7 8 class F { } foo()9int foo() 10 { 11 scope F f = new F(); // comment out and warning goes away 12 return 0; 13 } 14 15 /******************************************/ 16 foo2()17int foo2() 18 { 19 try 20 { 21 return 0; 22 } 23 finally { } 24 } 25 26 /******************************************/ 27 getNthInt(A...)28private int getNthInt(A...)(uint index, A args) 29 { 30 foreach (i, arg; args) 31 { 32 static if (is(typeof(arg) : long) || is(typeof(arg) : ulong)) 33 { 34 if (i != index) continue; 35 return cast(int)(arg); 36 } 37 else 38 { 39 if (i == index) break; 40 } 41 } 42 throw new Error("int expected"); 43 } 44 45 /******************************************/ 46 47 class Foo2 { foo()48 int foo() { 49 synchronized(this){ 50 return 8; 51 } 52 } 53 } 54 55 /******************************************/ 56 mainX()57void mainX() 58 { 59 int i=0; 60 printf("This number is zero: "); 61 goto inloop; 62 for(; i<10; i++) { // this is line 7 63 printf("This number is nonzero: "); 64 inloop: 65 printf("%d\n", i); 66 } 67 } 68 69 /******************************************/ 70 foo3(int bar)71string foo3(int bar) 72 { 73 switch (bar) 74 { 75 case 1: 76 return "1"; 77 case 2: 78 return "2"; 79 default: 80 return "3"; 81 } 82 } 83 84 85 /******************************************/ 86 foo4()87int foo4() 88 { 89 int i; 90 for (;; ++i) 91 { 92 if (i == 10) return 0; 93 } 94 } 95 96 /******************************************/ 97 foo5()98int foo5() 99 { 100 do { 101 if (false) 102 return 1; 103 } while (true); 104 } 105 106 /******************************************/ 107 foo6()108nothrow int foo6() 109 { 110 int x = 2; 111 try 112 { 113 } 114 catch(Exception e) 115 { 116 x = 4; 117 throw new Exception("xxx"); 118 } 119 return x; 120 } 121 122 /******************************************/ 123 // https://issues.dlang.org/show_bug.cgi?id=6518 124 TypeTuple(T...)125template TypeTuple(T...) { alias T TypeTuple; } test6518()126void test6518() 127 { 128 switch(2) 129 { 130 foreach(v; TypeTuple!(1, 2, 3)) 131 case v: break; 132 default: assert(0); 133 } 134 } 135 136 /******************************************/ 137 // https://issues.dlang.org/show_bug.cgi?id=7232 138 test7232()139bool test7232() 140 { 141 scope(failure) return false; 142 return true; 143 } 144 145 /***************************************************/ 146 147 struct S9332 148 { thisS9332149 this(S9332) 150 { 151 // while (1) { } 152 assert(0, "unreachable?"); 153 } 154 } 155 156 /******************************************/ 157 // https://issues.dlang.org/show_bug.cgi?id=13201 158 159 class C13201 160 { foo()161 void foo() 162 { 163 synchronized(this) 164 { 165 assert(0); 166 } 167 } 168 } 169 test13201a()170void test13201a() 171 { 172 auto c = new C13201(); 173 synchronized(c) 174 { 175 assert(0); 176 } 177 } 178 test13201b()179void test13201b() 180 { 181 struct S { ~this() {} } 182 183 S s; 184 assert(0); 185 } 186 187 /******************************************/ 188 main()189void main() 190 { 191 } 192