]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.dg/torture/pr96152.d
d: Move all runnable tests in gdc.dg to gdc.dg/torture
[thirdparty/gcc.git] / gcc / testsuite / gdc.dg / torture / pr96152.d
1 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96152
2 // { dg-additional-options "-fmain -funittest" }
3 // { dg-do run }
4 // { dg-skip-if "needs gcc/config.d" { ! d_runtime } }
5 auto assocArray(Keys, Values)(Keys keys, Values values)
6 {
7 void* aa;
8 {
9 if (values.length > keys.length)
10 values = values[0 .. keys.length];
11 else if (keys.length > values.length)
12 keys = keys[0 .. values.length];
13 aa = aaLiteral(keys, values);
14 }
15 alias Key = typeof(keys[0]);
16 alias Value = typeof(values[0]);
17 return (() @trusted => cast(Value[Key]) aa)();
18 }
19
20 @safe unittest
21 {
22 struct ThrowingElement
23 {
24 int i;
25 static bool b;
26 ~this(){
27 if (b)
28 throw new Exception("");
29 }
30 }
31 assert(assocArray([ThrowingElement()], [0]) == [ThrowingElement(): 0]);
32 }