[Issue 24362] casting a string literal with a postfix to array re-interpret casts anything

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 30 20:57:26 UTC 2024


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com

--- Comment #1 from Walter Bright <bugzilla at digitalmars.com> ---
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.

--


More information about the Digitalmars-d-bugs mailing list