Implicit conversion to mutable if no indirections?

Salih Dincer salihdb at hotmail.com
Sun Sep 4 12:24:26 UTC 2022


On Sunday, 4 September 2022 at 11:03:53 UTC, Nick Treleaven wrote:
> ```d
> const i = 4; // const int
> auto v = i;  // int
> const a = [0]; // const(int[])
> auto s = a;    // const(int)[]
> ```
P
I got different results.  Which compiler are you using?  For 
example, the content of v cannot be changed:

```d
void main()
{
   const i = 4;   // const(int)
   auto v = i;    // const(int)
   /* onlineapp.d(6): Error: cannot modify `const` expression `v`
     --v; //*/
   const a = [0]; // const(const(int)[])
   auto b = a;    // const(const(int)[])

   const c = [i]; // const(const(int)[])
   auto d = c;    // const(const(int)[])
   //typeid(d).writeln;
}
```

SDB at 79


More information about the Digitalmars-d mailing list