Tango error : cannot modify immutable expression *p++

Jacob Carlborg doob at me.com
Fri Sep 11 18:38:39 UTC 2020


On 2020-09-10 22:55, jeromeG wrote:
> Hi people,
> 
> I am using the tango-1.0.5_2.0.85 package in my project, for some 
> reasons :)
> 
> This packages contains tango/tango/text/convert/Float.d
> 
> 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 guess 
> the error pops up because the template argument passed as T is immutable 
> itself. But in this case, I don't see how we can return a modified dst 
> at any point.

I'm guessing `T` should to be `char`. There are some examples at the 
bottom how to use it:

https://github.com/SiegeLord/Tango-D2/blob/6a9efb86a0789fb2e32ef869e647e7de97b5e26b/tango/text/convert/Float.d#L855

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list