digitalmars.D.bugs - [Issue 17920] New: Missing postblit for `T lhs = cast(T) <const(T)
- d-bugmail puremagic.com (52/52) Oct 20 2017 https://issues.dlang.org/show_bug.cgi?id=17920
https://issues.dlang.org/show_bug.cgi?id=17920 Issue ID: 17920 Summary: Missing postblit for `T lhs = cast(T) <const(T) rhsLValue>` Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: major Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: kinke gmx.net Casting away the constness from a right-hand-side lvalue skips the required postblit call: ``` import core.stdc.stdio; int postblit = 0, dtor = 0; struct S { uint val; this(this) { ++postblit; ++val; } ~this() { ++dtor; } } void foo(S s) { const fromMutable = cast(S) s; printf("fromMutable.val: %d\n", fromMutable.val); } void fooConst(const S s) { const fromConst = cast(S) s; printf("fromConst.val: %d\n", fromConst.val); } void main() { const x = S(100); foo(x); printf("postblit: %d, dtor: %d\n", postblit, dtor); fooConst(x); printf("postblit: %d, dtor: %d\n", postblit, dtor); } ``` DMD 2.076.1 yields: ``` fromMutable.val: 102 postblit: 2, dtor: 2 fromConst.val: 101 postblit: 3, dtor: 4 ``` --
Oct 20 2017