www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22117] New: Can't store scope pointer in a SumType

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 puremagic.com
          Reporter: snarwin+bugzilla 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`.

--
Jul 11