Tango error : cannot modify immutable expression *p++

Paul Backus snarwin at gmail.com
Thu Sep 10 21:00:21 UTC 2020


On Thursday, 10 September 2020 at 20:55:17 UTC, jeromeG wrote:
> I was just compiling my program and got this error:
>
> ../../../.dub/packages/tango-1.0.5_2.0.85/tango/tango/text/convert/Float.d(251,13): Error: cannot modify immutable expression *p++
>
> In fact, there are a dozen similar errors with Float.d, because 
> the code shows the following in different places:
>
> -----
>         auto p = dst.ptr;
>         if (sign)
>             *p++ = '-'; <<< this is problematic
> -----
>
> dst is from the function argument list :
>
> T[] format(T) (T[] dst, NumType x, int decimals=Dec, int e=Exp, 
> bool pad=Pad)
>
>
> I don't understand why dst is immutable at the first place...

I haven't used Tango, but my guess is it's because strings are 
immutable in D2, but used to be mutable in D1.


More information about the Digitalmars-d mailing list