[Issue 21561] New: Unsafe aliasing of immutable union member allowed in @safe code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jan 20 18:02:38 UTC 2021
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: nobody at puremagic.com
Reporter: snarwin+bugzilla at 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
--
More information about the Digitalmars-d-bugs
mailing list