https://issues.dlang.org/show_bug.cgi?id=13488
Kenji Hara <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|[reg] implicit conversions |implicit conversions to |to immutable broken |immutable broken --- Comment #2 from Kenji Hara <[email protected]> --- There's > struct T { > const(int)* p = null; > this(const(int)* q) pure { > p = q; > } > } When we see only the signature (const(int*)) pure, the constructor cannot construct immutable object in general, because the parameter q may receive mutable object. If you want to restrict constructed object qualifier by using constructor argument qualifiers, you can use inout constructor. struct T { const(int)* p = null; this(inout(int)* q) inout// pure { p = q; } } void foo() { int x; T mt1 = T(&x); // ok T* mp1 = new T(&x); // ok //T mt2 = immutable T(&x); // NG //T* mp2 = new immutable T(&x); // NG immutable int y; //immutable(T) it1 = T(&y); // NG //immutable(T)* ip1 = new T(&y); // NG immutable(T) it2 = immutable T(&y); // ok immutable(T)* ip2 = new immutable T(&y); // ok } --
