February 26, 2021
https://issues.dlang.org/show_bug.cgi?id=21664

          Issue ID: 21664
           Summary: Unsafe global 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:

---
int* p = cast(int*) 0xDEADBEEF;
void main() @safe
{
    int n = *p;
}
---

To prevent this, the compiler must forbid access to global variables in @safe code unless it can prove that they have safe values. [1]

[1] https://dlang.org/spec/function.html#safe-values

--