Bug 20569 – [DIP1000] allow taking the address of a `scope` struct field if it has no indirections

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-02-08T20:41:45Z
Last change time
2020-02-09T03:52:38Z
Keywords
pull, safe
Assigned to
No Owner
Creator
ag0aep6g

Comments

Comment #0 by ag0aep6g — 2020-02-08T20:41:45Z
This came up in the forum: https://forum.dlang.org/post/[email protected] 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.
Comment #1 by dlang-bot — 2020-02-08T20:46:29Z
@aG0aep6G created dlang/dmd pull request #10773 "fix issue 20569 - [DIP1000] allow taking the address of a `scope` str…" fixing this issue: - fix issue 20569 - [DIP1000] allow taking the address of a `scope` struct field if it has no indirections https://github.com/dlang/dmd/pull/10773
Comment #2 by dlang-bot — 2020-02-09T03:52:38Z
dlang/dmd pull request #10773 "fix issue 20569 - [DIP1000] allow taking the address of a `scope` str…" was merged into master: - c1a9253d649353931b47a4577ba1295119e67028 by aG0aep6G: fix issue 20569 - [DIP1000] allow taking the address of a `scope` struct field if it has no indirections https://github.com/dlang/dmd/pull/10773