This should not compile:
@safe:
void main() {
const int i = 3;
int* q = &cast()i; // this should not compile in @safe code
*q = 4; // oops
bar(i);
}
void bar(ref const int i) { assert(i == 3); } // fails at runtime
@ntrel created dlang/dmd pull request #16315 "Fix Bugzilla 24434 - Casting away const with cast() is not a @safe lv…" fixing this issue:
- Fix Bugzilla 24434 - Casting away const with cast() is not a @safe lvalue
https://github.com/dlang/dmd/pull/16315
Comment #3 by dlang-bot — 2024-04-28T14:44:56Z
dlang/dmd pull request #16315 "Fix Bugzilla 24434 - Casting away const with cast() is not a @safe lv…" was merged into master:
- 2b65bccc71a22fec0bff58b7c40662701941adf4 by Nick Treleaven:
Fix Bugzilla 24434 - Casting away const with cast() is not a @safe lvalue
https://github.com/dlang/dmd/pull/16315