Bug 23202 – catch null dereferences at compille time

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-06-21T08:05:58Z
Last change time
2024-12-13T19:23:30Z
Assigned to
No Owner
Creator
Jan Jurzitza
Moved to GitHub: dmd#20123 →

Comments

Comment #0 by d.bugs — 2022-06-21T08:05:58Z
Example code: ``` @safe: class S { string str; } void main() { auto s = S.init.tupleof; } ```
Comment #1 by dkorpel — 2022-06-21T11:48:44Z
S.init is `null`, which you dereference by accessing a member. `@safe` does not prevent `null` dereferences, since those only abort the program, they don't corrupt memory. The code is essentially doing this: ``` auto s = (cast(S)null).str; ``` Changing this to an enhancement.
Comment #2 by robert.schadek — 2024-12-13T19:23:30Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20123 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB