Issue 24665 - Static array cast can be an unsafe lvalue
Summary: Static array cast can be an unsafe lvalue
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: safe
Depends on:
Blocks:
 
Reported: 2024-07-16 18:39 UTC by Nick Treleaven
Modified: 2024-11-19 22:05 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Nick Treleaven 2024-07-16 18:39:35 UTC
Both the cast assignments below corrupt the address of the Object reference in c[0]. They should be rejected in @safe code.

void main() @safe
{
    Object[1] c;
    (cast(size_t[1]) c) = 2; //!
    (cast(size_t[1]) c)[0] = 2; //!
}

Note that when used as an rvalue, the casts are OK.