[Issue 17654] return value incorrectly considered unique when casting to another pointer type

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Jul 15 05:58:51 PDT 2017


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

--- Comment #2 from ag0aep6g at gmail.com ---
(In reply to Steven Schveighoffer from comment #1)
> I actually think it's a design problem. assumeUTF is marked pure. The input
> is ubyte and the output is char. This means the compiler can reasonably
> assume the output is unrelated to the input and therefore unique. 
> 
> This is quite a pickle. We can't very well unmark it pure, and I think the
> compiler logic is sound.

I don't agree that the compiler logic is sound. The casts are valid. The
compiler cannot assume that they don't occur.

It even happens with classes (no cast needed):

----
class B { int x; }
class C : B {}

B toB(C c) pure { return c; }

void main()
{
    C c = new C;
    c.x = 1;
    immutable B b = toB(c); /* should be rejected */
    assert(b.x == 1); /* passes */
    c.x = 2;
    assert(b.x == 1); /* fails */
}
----

--


More information about the Digitalmars-d-bugs mailing list