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 } } assocArray(Keys,Values)5auto 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; ~thisThrowingElement26 ~this(){ 27 if (b) 28 throw new Exception(""); 29 } 30 } 31 assert(assocArray([ThrowingElement()], [0]) == [ThrowingElement(): 0]); 32 } 33