[Issue 24445] New: Type cast dropping const should not be an lvalue

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 20 17:23:44 UTC 2024


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

          Issue ID: 24445
           Summary: Type cast dropping const should not be an lvalue
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: nick at geany.org

The docs say the result is an lvalue for:

> cast(U) expressions applied to lvalues of type T when T* is implicitly convertible to U*;

https://dlang.org/spec/expression.html#.define-lvalue

const int* does not implicitly convert to int*, yet:

void main()
{
    const int i;
    cast(int) i = 2;
    assert(i == 0); // passes
}

The cast is making a hidden copy, which should be an rvalue. So the assignment
should error.

--


More information about the Digitalmars-d-bugs mailing list