Escaping the Tyranny of the GC: std.rcstring, first blood

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 21 06:19:41 PDT 2014


On 09/21/2014 11:53 AM, Rainer Schuetze wrote:
>
> It also references the issue why this has been changed pretty recently:
> https://issues.dlang.org/show_bug.cgi?id=11257
>
> I'm on the fence whether this is convenient or makes it too easy to
> break const "guarantees". It seems strange that you can modify a
> const-reference only after you make a copy of the "pointer". ATM I'd
> prefer seeing an explicite cast for that.

This change is unsound.

import std.variant;

void foo(const(Algebraic!(int*,const(int)*)) x)@safe{
     Algebraic!(int*,const(int)*) y=x;
     *y.get!(int*)()=2;
}

void main()@safe{
     auto x=Algebraic!(int*,const(int)*)(new int);
     assert(*x.get!(int*)()==0); // pass
     foo(x); // passed as const, so shouldn't change
     assert(*x.get!(int*)()==2); // pass!
}



More information about the Digitalmars-d mailing list