https://issues.dlang.org/show_bug.cgi?id=21561
Issue ID: 21561 Summary: Unsafe aliasing of immutable union member allowed in @safe code Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nob...@puremagic.com Reporter: snarwin+bugzi...@gmail.com Example program: --- union U { int x; immutable int y; } void example() @safe { U a = { x: 0 }; int n = a.y; } --- Access to `a.y` should be forbidden in @safe code according the the language spec's definition of safe aliasing [1], which permits aliasing between types with different mutability qualifiers only when > * both types are const or immutable; or > * one of the types is mutable while the other is a const-qualified basic data > type [1] https://dlang.org/spec/function.html#safe-aliasing --