Bug 23434 – [DIP1000] Allow storing scope and non-scope data in same aggregate

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-10-23T19:57:13Z
Last change time
2024-12-13T19:25:08Z
Assigned to
No Owner
Creator
Paul Backus
Moved to GitHub: dmd#18130 →

Comments

Comment #0 by snarwin+bugzilla — 2022-10-23T19:57:13Z
As of DMD 2.100.2, the following program fails to compile even with `-preview=dip1000`: --- struct S { int* a, b; } int* example(int* p) @safe { int n; scope int* sp = &n; S s; s.a = sp; // s inferred as scope s.b = p; return s.b; } --- The error message is: --- bug.d(13): Error: scope variable `s` may not be returned --- This error occurs because the compiler does not distinguish between the lifetimes of `s.a` and `s.b`. While `s.a` is scope, and cannot safely be returned, there would be no danger in allowing the function to return `s.b`. Currently, this limitation can be worked around by splitting `s` into separate variables, or by using `@trusted`.
Comment #1 by robert.schadek — 2024-12-13T19:25:08Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18130 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB