Bug 24362 – casting a string literal with a postfix to array re-interpret casts anything

Status
NEW
Severity
major
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-01-30T13:08:00Z
Last change time
2024-12-13T19:32:55Z
Keywords
ice
Assigned to
No Owner
Creator
Dennis
See also
https://issues.dlang.org/show_bug.cgi?id=24361
Moved to GitHub: dmd#18209 →

Comments

Comment #0 by dkorpel — 2024-01-30T13:08:00Z
dmd currently allows casting a string literal with a postfix to any array. It re-interpret casts and creates a StringExp with types and sizes that the frontend can't handle. ```D auto v0 = cast(float[1]) "abcd"c; // re-interpret casts string bytes to float auto v1 = cast(ubyte[300][2]) "abcd"c; // assert failure in dcast.d void main() { auto v2 = cast(long[2]) "abcd"c; // assert failure in backend } ```
Comment #1 by bugzilla — 2024-01-30T20:57:26Z
This should work: > auto v0 = cast(float[1]) "abcd"c; // re-interpret casts string bytes to float This should not compile: > auto v1 = cast(ubyte[300][2]) "abcd"c; // assert failure in dcast.d This should not compile: > auto v2 = cast(long[2]) "abcd"c; // assert failure in backend The rule for array casting is the size of the result should match the size of the operand.
Comment #2 by robert.schadek — 2024-12-13T19:32:55Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18209 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB