Copying to an immutable array in a costructor

Maxim Fomin maxim at maxim-fomin.ru
Thu Oct 24 04:42:07 PDT 2013


On Thursday, 24 October 2013 at 10:58:30 UTC, bearophile wrote:
> Jonathan M Davis:
>
>> It's a compiler bug. immutable data should not be initialized 
>> more than once.
>
> My point was another one, regarding this refused code:
>
>
> import std.algorithm: copy;
> immutable int[2] data;
> static this() {
>     [10, 20].copy(data[]); // Error.
> }
> void main() {}
>
>
> Bye,
> bearophile

Reduced:

immutable int[] data;

void foo(int[] data) {}

static this()
{
	foo(data);
}


More information about the Digitalmars-d-learn mailing list