[D1] assert failure expression.c

bearophile bearophileHUGS at lycos.com
Sat Oct 9 10:49:18 PDT 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


More information about the Digitalmars-d-learn mailing list