digitalmars.D.bugs - [Issue 21675] New: Unsafe aggregate field initializer causes
- d-bugmail puremagic.com (33/33) Mar 02 2021 https://issues.dlang.org/show_bug.cgi?id=21675
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 puremagic.com Reporter: snarwin+bugzilla 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 --
Mar 02 2021