Implicit conversion from const to mutable

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 17 13:22:09 PDT 2017


On 8/17/17 3:24 PM, Balagopal Komarath wrote:
> Is it possible to make structs containing slices support implicit 
> conversion from const to mutable?

This should "work". I don't think your static assert will pass, but the 
main function below should run.

struct A
{
    int[] a;
    A dup() const
    {
        return A(a.dup);
    }
    alias dup this;
}

void main()
{
	const A a;
	A a2 = a;
}

However, this results in a segfault as far back as 2.064, and 2.063 
doesn't seem to like it (but maybe because alias this wasn't supported? 
I'm not sure).

https://issues.dlang.org/show_bug.cgi?id=17759

-Steve


More information about the Digitalmars-d-learn mailing list