D does have head const (but maybe it shouldn't)

ag0aep6g anonymous at example.com
Thu Dec 31 16:40:07 UTC 2020


On 30.12.20 23:49, Timon Gehr wrote:
> ---
> // https://issues.dlang.org/show_bug.cgi?id=2947
> class C{ int*[] a=[null]; }
> auto f(int* x)pure @safe{
>      (new C).a[0]=x;
>      return x;
> }
> void g(const(int)* y)pure @safe{
>      *(new C).a[0]=2;
> }
> ---

This is my favorite of the bunch. Ancient issue, many duplicates, has 
been argued to be working as intended, no fix on the horizon. It's lovely.

D does not have head const ... except when it does.
In D, `pure` functions cannot access global mutable state ... except 
when they can.


More information about the Digitalmars-d mailing list