[Issue 21675] New: Unsafe aggregate field initializer causes undefined behavior in @safe code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Mar 2 14:45:57 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21675
Issue ID: 21675
Summary: Unsafe aggregate field initializer causes undefined
behavior in @safe code
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: snarwin+bugzilla at gmail.com
As of DMD 2.095.0, the following program compiles and exhibits undefined
behavior at runtime:
---
struct S
{
int* p = cast(int*) 0xDEADBEEF;
}
@safe void main()
{
S s;
int n = *s.p;
}
---
To prevent this, the compiler must either forbid default initialization of
types with unsafe `.init` values, or enforce that all default initializers are
safe values. [1]
Related: issue 21664.
[1] https://dlang.org/spec/function.html#safe-values
--
More information about the Digitalmars-d-bugs
mailing list