string foo(in string s)
{
return s;
}
void main()
{
import std.stdio;
string[] result;
foreach(c; "hello")
{
result ~= foo([c]);
}
writeln(result);
}
With no previews, preview=dip1000, or preview=in, this outputs: ["h", "e", "l", "l", "o"]
With both preview=dip1000 and preview=in, this outputs: ["o", "o", "o", "o", "o"]
What is happening is the compiler is somehow convinced that it can allocate the array literal on the stack (and overwrites that literal each loop).
I know this isn't @safe
code, but @system
code shouldn't be made less safe by the preview switches!
I know people write in
instead of const
all the time simply because it's shorter.
Thoughts?
-Steve