digitalmars.D.bugs - [Issue 20347] New: Initialization of globals not checked for safe,
- d-bugmail puremagic.com (41/41) Nov 02 2019 https://issues.dlang.org/show_bug.cgi?id=20347
https://issues.dlang.org/show_bug.cgi?id=20347 Issue ID: 20347 Summary: Initialization of globals not checked for safe, round 2 Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: safe Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: ag0aep6g gmail.com This was found by dkorpel while working on a DIP: https://github.com/dlang/DIPs/blob/7b109744db7fd0cfea9904354613a50e7dbdad08/DIPs/DIP1NNN-DK.md#existing-holes-in-safe The fix for issue 19646 outlaws this code: ---- safe: const x = 42; int* y = cast(int*) &x; /* Error: cast from const(int)* to int* not allowed in safe code */ void main() { *y = 7; } ---- But the following two slight variations still pass. 1) Applying ` safe` individually: ---- safe const x = 42; safe int* y = cast(int*) &x; /* Should be rejected. */ safe void main() { *y = 7; } ---- 2) Calling an system function in the initializer: ---- system int* f() { return cast(int*) &x; } safe: const x = 42; int* y = f(); /* Should be rejected. */ void main() { *y = 7; } ---- --
Nov 02 2019