[Issue 23182] New: Can't assign struct with opAssign to SumType in CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 13 21:44:38 UTC 2022


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

          Issue ID: 23182
           Summary: Can't assign struct with opAssign to SumType in CTFE
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

As of DMD 2.100.0, the following program fails to compile:

---
import std.sumtype;

struct HasOpAssign
{
        void opAssign(HasOpAssign rhs) {}
}

SumType!HasOpAssign test()
{
        SumType!HasOpAssign s;
        s = HasOpAssign();
        s = SumType!HasOpAssign();
        return s;
}

void main()
{
        enum result = test();
}
---

The error message is

---
/usr/include/dmd/druntime/import/core/lifetime.d(2210): Error: `memcpy` cannot
be interpreted at compile time, because it has no available source code
bug.d(18):        compile time context created here
---

The cause is calls to core.lifetime.move and core.lifetime.forward in SumType's
opAssign overload. Because of issue 21542, these calls cannot be evaluated in
CTFE.

--


More information about the Digitalmars-d-bugs mailing list