[Issue 22117] New: Can't store scope pointer in a SumType

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 12 00:29:11 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22117

          Issue ID: 22117
           Summary: Can't store scope pointer in a SumType
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

As of DMD 2.097.0, the following program fails to compile with
`-preview=dip1000`:

---
void main() @safe
{
    import std.sumtype;
    int n = 123;
    SumType!(int*) s = &n;
}
---

The error message is:

---
Error: reference to local variable `n` assigned to non-scope parameter `value`
calling std.sumtype.SumType!(int*).SumType.this
---

Since the sumtype instance `s` is a local variable with shorter lifetime than
`n`, it should be able to store a pointer to `n`.

--


More information about the Digitalmars-d-bugs mailing list