D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6092 - Can't cast primitive to same-sized static array
Summary: Can't cast primitive to same-sized static array
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
: 7328 (view as issue list)
Depends on:
Blocks:
 
Reported: 2011-06-02 13:38 UTC by Nick Sabalausky
Modified: 2024-12-13 17:55 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Nick Sabalausky 2011-06-02 13:38:32 UTC
This works, and is a very useful trick:

struct Foo {uint f;}
void main(){
    Foo a;
    ubyte[] b = cast(ubyte[4])a;
}

However, the following generates an error:

void main(){
    uint a;
    ubyte[] b = cast(ubyte[4])a;
}

The error:
Error: e2ir: cannot cast a of type uint to type ubyte[4u]
Comment 1 Denis Shelomovskii 2013-11-09 10:57:08 UTC
A report for e2ir ICE from original testcase: Issue 11484
Comment 2 Kenji Hara 2015-06-22 05:38:11 UTC
From the past, DMD glue layer does not support a cast from primitive type to static array. And from 2.065, it's changed to semantic error.

Therefore, the rejection is intentional. Downgrade to enhancement issue.
Comment 3 basile-z 2020-02-20 12:23:00 UTC
*** Issue 7328 has been marked as a duplicate of this issue. ***
Comment 4 dlangBugzillaToGithub 2024-12-13 17:55:25 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18345

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB