D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20569 - [DIP1000] allow taking the address of a `scope` struct field if it has no indirections
Summary: [DIP1000] allow taking the address of a `scope` struct field if it has no ind...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull, safe
Depends on:
Blocks:
 
Reported: 2020-02-08 20:41 UTC by ag0aep6g
Modified: 2020-02-09 03:52 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ag0aep6g 2020-02-08 20:41:45 UTC
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.
Comment 1 Dlang Bot 2020-02-08 20:46:29 UTC
@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 Dlang Bot 2020-02-09 03:52:38 UTC
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