[Issue 19754] cast() sometimes yields lvalue, sometimes yields rvalue

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 24 12:24:19 UTC 2019


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

--- Comment #6 from Andrei Alexandrescu <andrei at erdani.com> ---
>That's very true, however in this case it'd be bought by making the semantics of cast much more complicated. I.E. the complexity of __mutable would be pushed into cast, considering that people relay on cast to work properly and intuitively whereas __mutable is not relied upon by anyone; Such changes should be considered carefully.

This is nonsense, sigh. Can't even start to debate... There's no complexity
tossed around? What's proper and intuitive and what isn't?

Applied to primitive types, cast() and cast(qualifier) are currently
meaningless.

    immutable int a;
    auto b = cast() a;
    auto c = int(a);
    assert(is(typeof(b) == typeof(c)));

That cast didn't really cast anything because the same code can be written
without. Same goes the other way:

    int a;
    auto b = cast(immutable) a;
    immutable c = a;
    assert(is(typeof(b) == typeof(c)));

Again, a nominal cast that really doesn't cast.

--


More information about the Digitalmars-d-bugs mailing list