import std.stdio;

string func()
{
        string s="abc";
        return s;
}

void func1()
{
        writefln("func1");
        string v = func();
        writefln("call func");
        writefln(func2());
}

byte[] func2()
{
        writefln("hello!");
        byte[16] v= [65,65,65,65,
                     65,65,65,65,
                     65,65,65,65,
                     65,65,65,65];
        writefln(v[0..16]);
        return v[0..16];
}

void main(string[] args)
{
        func1();
}

The culprit is the on stack array.

Should the compiler warn on slicing on a fixed length array? or even give an error? I find this use case can easily go wrong! You may even think this code is correct at the very first glance.

Reply via email to