[Issue 23530] casting immutable away allowed in safe

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 2 12:15:35 UTC 2022


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

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305 at gmail.com> ---
dip1000 is not needed to reproduce this:

@safe void main()
{   immutable int x = 5; //alternatively const
    int* b = &(cast()x);                                                        
}

This used to fail compilation with a wrong error message: Error: `cast(int)x`
is not an lvalue and cannot be modified.

So I assume that at some point it wasn't possible to take the address of a
cast. When safe was implemented they probably took this into account and later
on when the cast was allowed someone probably forgot to update the safety
check.

--


More information about the Digitalmars-d-bugs mailing list