The following snipped fails to compile. What seems to happen is that the return statement implicitly calls the constructor which in turn returns a mutable S which is not implicitly castable to immutable - thus the error. Happens since DMD 2.054 --- struct S { int[] c; this(in S){} immutable(S) f() const { S s; return cast(immutable)s; // the following works: //immutable(S) sr = cast(immutable)s; //return sr; } } --- dbug2.d(6): Error: cannot implicitly convert expression ((immutable immutable(S) __ctmp3 = 0; , __ctmp3).this(s)) of type S to immutable(S) .. leaving the severity as normal, as there is an easy workaround
The provided code compiles and runs as of v2.065.