Re: @nogc inconsistent for array comparison depending on mutability of elements

2016-04-08 Thread Dicebot via Digitalmars-d-learn
On Friday, 8 April 2016 at 12:45:59 UTC, Xinok wrote: On Friday, 8 April 2016 at 10:15:10 UTC, Dicebot wrote: On Friday, 8 April 2016 at 09:56:41 UTC, Nick Treleaven wrote: Semantically, array literals are always allocated on the heap. In this case, the optimizer can obviously place the array

Re: @nogc inconsistent for array comparison depending on mutability of elements

2016-04-08 Thread Xinok via Digitalmars-d-learn
On Friday, 8 April 2016 at 10:15:10 UTC, Dicebot wrote: On Friday, 8 April 2016 at 09:56:41 UTC, Nick Treleaven wrote: Semantically, array literals are always allocated on the heap. In this case, the optimizer can obviously place the array on the stack or even make it static/global. So @nogc

Re: @nogc inconsistent for array comparison depending on mutability of elements

2016-04-08 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 8 April 2016 at 10:11:43 UTC, Rene Zwanenburg wrote: On Friday, 8 April 2016 at 09:56:41 UTC, Nick Treleaven wrote: If the comparison with b shouldn't be allowed, I suggest we add opEquals to std.range.only. This removes a need to import std.algorithm.equal and reduces bracket

Re: @nogc inconsistent for array comparison depending on mutability of elements

2016-04-08 Thread Dicebot via Digitalmars-d-learn
On Friday, 8 April 2016 at 09:56:41 UTC, Nick Treleaven wrote: Semantically, array literals are always allocated on the heap. In this case, the optimizer can obviously place the array on the stack or even make it static/global. So @nogc is enforced by the optimizer? Yes, sadly. To make it

Re: @nogc inconsistent for array comparison depending on mutability of elements

2016-04-08 Thread Rene Zwanenburg via Digitalmars-d-learn
On Friday, 8 April 2016 at 09:56:41 UTC, Nick Treleaven wrote: If the comparison with b shouldn't be allowed, I suggest we add opEquals to std.range.only. This removes a need to import std.algorithm.equal and reduces bracket nesting: assert(b == only(1, 2)); equal[1] can compare ranges of

Re: @nogc inconsistent for array comparison depending on mutability of elements

2016-04-08 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 8 April 2016 at 03:14:40 UTC, Xinok wrote: On Friday, 8 April 2016 at 01:36:18 UTC, rcorre wrote: @nogc unittest { int[2] a = [1, 2]; assert(a == [1, 2]); // OK immutable(int)[2] b = [1, 2]; assert(b == [1, 2]); // fail: array literal may cause allocation } Is

Re: @nogc inconsistent for array comparison depending on mutability of elements

2016-04-07 Thread Xinok via Digitalmars-d-learn
On Friday, 8 April 2016 at 01:36:18 UTC, rcorre wrote: @nogc unittest { int[2] a = [1, 2]; assert(a == [1, 2]); // OK immutable(int)[2] b = [1, 2]; assert(b == [1, 2]); // fail: array literal may cause allocation } Is there any logic behind allowing the comparison with `a`

@nogc inconsistent for array comparison depending on mutability of elements

2016-04-07 Thread rcorre via Digitalmars-d-learn
@nogc unittest { int[2] a = [1, 2]; assert(a == [1, 2]); // OK immutable(int)[2] b = [1, 2]; assert(b == [1, 2]); // fail: array literal may cause allocation } Is there any logic behind allowing the comparison with `a` but not `b`, or is this a compiler bug?