Bug 24434 – Casting away const with cast() should not produce an lvalue

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-03-10T19:28:46Z
Last change time
2024-04-28T14:44:56Z
Keywords
pull, safe
Assigned to
No Owner
Creator
Walter Bright
See also
https://issues.dlang.org/show_bug.cgi?id=19754

Comments

Comment #0 by bugzilla — 2024-03-10T19:28:46Z
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
Comment #1 by bugzilla — 2024-03-10T19:30:15Z
This is possibly a regression resulting from https://issues.dlang.org/show_bug.cgi?id=19754
Comment #2 by dlang-bot — 2024-03-16T12:36:49Z
@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