On Friday, 1 April 2016 at 07:58:46 UTC, ZombineDev wrote:
On Friday, 1 April 2016 at 05:00:43 UTC, ag0aep6g wrote:
int[] f() pure nothrow {return [0];}
[snip]
The last case is different. It has nothing to do with pure. It is about reference-type literals and default field values:
[snip]
struct S
{
    C c = new C;
    int[] arr = [1, 2, 3];
}

No. Try this:


int[] bar() {
    return [0];
}

void main() {
    auto a = bar();
    a[0] = 3;
    auto b = bar();
    assert(b[0] == 0);
}

That assert passes with flying colors no matter the compiler flags.

It is true that arrays in structs' initial state are copied (and may lead to subtle bugs), but the same is not the case for arrays returned from functions.

--
  Simen

Reply via email to