digitalmars.D.bugs - [Issue 20569] New: [DIP1000] allow taking the address of a `scope`
- d-bugmail puremagic.com (38/38) Feb 08 2020 https://issues.dlang.org/show_bug.cgi?id=20569
https://issues.dlang.org/show_bug.cgi?id=20569 Issue ID: 20569 Summary: [DIP1000] allow taking the address of a `scope` struct field if it has no indirections Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: safe Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: ag0aep6g gmail.com This came up in the forum: https://forum.dlang.org/post/r1lkbt$2vmk$1 digitalmars.com As far as I can tell, this can be allowed without compromising safety: ---- void main() safe { static struct S { int value; int* pointer; } /* explicit `scope`: */ scope S s1; scope int* p1 = &s1.value; /* Error: cannot take address of scope local */ /* inferred `scope`: */ int x; S s2 = S(0, &x); int* p2 = &s2.value; /* Error: cannot take address of scope local */ } ---- The `scope` on `s1` and `s2` really just applies to the `pointer` field. It can be ignored for the `value` field. --
Feb 08 2020