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: [email protected]
Reporter: [email protected]
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.
--