July 12, 2011 [Issue 6300] New: Returning a cast(immutable) struct erroneously calls a matching constructor | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=6300 Summary: Returning a cast(immutable) struct erroneously calls a matching constructor Product: D Version: unspecified Platform: Other OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: ludwig@informatik.uni-luebeck.de --- Comment #0 from Sönke Ludwig <ludwig@informatik.uni-luebeck.de> 2011-07-12 12:40:53 PDT --- 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 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation