[Issue 19666] New: Compiler executes illegal instruction casting array to struct pointer
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 11 02:07:42 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19666
Issue ID: 19666
Summary: Compiler executes illegal instruction casting array to
struct pointer
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: andy.pj.hanson at gmail.com
```
struct StoreAny {
enum size_t maxSize = (void*).sizeof;
enum size_t maxAlign = (void*).alignof;
align(maxAlign) ubyte[maxSize] store;
@trusted this(T)(T value) {
static assert(T.sizeof <= maxSize && T.alignof <= maxAlign);
*(cast(T*) store) = value;
}
@trusted T as(T)() {
return *(cast(T*) store);
}
}
struct SomeStruct { int x; }
enum StoreAny someEnum = StoreAny(SomeStruct());
void main() {
}
```
Compiling this code causes the compiler to terminate with SIGILL.
There is no error if I instantiate with a primitive, e.g. `StoreAny(0)`.
--
More information about the Digitalmars-d-bugs
mailing list