digitalmars.D.learn - [D1] assert failure expression.c
- %u (25/25) Oct 09 2010 Incomplete mixin expression + char[] to char assignment = crash :)
- bearophile (14/24) Oct 09 2010 You (or me or someone else) may add this to Bugzilla:
- bearophile (9/20) Oct 09 2010 Further reduced:
- %u (6/30) Oct 09 2010 bar() is allocated on the stack, so if you convert a static array to a d...
Incomplete mixin expression + char[] to char assignment = crash :) -- char[] foo() { char[2] res = "1 "; res[1] = ";"; // should be a char return res; } struct S(T) { int i = mixin( foo() ); // incomplete mixin expression } S!(int) s; -- Assertion failure: '0' on line 1342 in file 'expression.c' And while you are reading this, could you maybe tell me why this needs a .dup? -- char[] bar() { char[8] res = "int i=0;"; return res.dup;// without: main.d(/here/): Error: escaping reference to local res } mixin ( bar() ); --
Oct 09 2010
%u:Incomplete mixin expression + char[] to char assignment = crash :)You (or me or someone else) may add this to Bugzilla: char[2] foo() { char[2] code; code[1] = ""; return code; } struct Bar { int i = mixin(foo()); } void main() {}And while you are reading this, could you maybe tell me why this needs a .dup? -- char[] bar() { char[8] res = "int i=0;"; return res.dup;// without: main.d(/here/): Error: escaping reference to local res } mixin ( bar() );If bar() returns a char[], it means it returns a dynamic array. char[8] inside bar() is allocated on the stack, so if you convert a static array to a dynamic array, it doesn't get copied (no return by value), the dynamic array is just a reference to the stack memory, and this is a bug. If bar returns a char[8] there is no error in D2 because fixed-sized arrays get copied by value. Bye, bearophile
Oct 09 2010
You (or me or someone else) may add this to Bugzilla: char[2] foo() { char[2] code; code[1] = ""; return code; } struct Bar { int i = mixin(foo()); } void main() {}Further reduced: void foo() { char[0] code; code[0] = ""; } struct Bar { int i = mixin(foo()); } void main() {}
Oct 09 2010
Done & Thanks! == Quote from bearophile (bearophileHUGS lycos.com)'s article%u:bar() is allocated on the stack, so if you convert a static array to a dynamic array, it doesn't get copied (no return by value), the dynamic array is just a reference to the stack memory, and this is a bug. If bar returns a char[8] there is no error in D2 because fixed-sized arrays get copied by value.Incomplete mixin expression + char[] to char assignment = crash :)You (or me or someone else) may add this to Bugzilla: char[2] foo() { char[2] code; code[1] = ""; return code; } struct Bar { int i = mixin(foo()); } void main() {}And while you are reading this, could you maybe tell me why this needs a .dup? -- char[] bar() { char[8] res = "int i=0;"; return res.dup;// without: main.d(/here/): Error: escaping reference to local res } mixin ( bar() );If bar() returns a char[], it means it returns a dynamic array. char[8] insideBye, bearophile
Oct 09 2010