Bug 23182 – Can't assign struct with opAssign to SumType in CTFE

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-06-13T21:44:38Z
Last change time
2022-06-14T04:39:04Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus

Comments

Comment #0 by snarwin+bugzilla — 2022-06-13T21:44:38Z
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.
Comment #1 by dlang-bot — 2022-06-13T22:01:36Z
@pbackus created dlang/phobos pull request #8474 "Fix Issue 23182 - Can't assign struct with opAssign to SumType in CTFE" fixing this issue: - Fix Issue 23182 - Can't assign struct with opAssign to SumType in CTFE SumType.opAssign now avoids calling core.lifetime.move or core.lifetime.forward during CTFE whenever possible. https://github.com/dlang/phobos/pull/8474
Comment #2 by dlang-bot — 2022-06-14T04:39:04Z
dlang/phobos pull request #8474 "Fix Issue 23182 - Can't assign struct with opAssign to SumType in CTFE" was merged into master: - 7022304c0ec10050aedaa007069d88750046e6ba by Paul Backus: Fix Issue 23182 - Can't assign struct with opAssign to SumType in CTFE SumType.opAssign now avoids calling core.lifetime.move or core.lifetime.forward during CTFE whenever possible. https://github.com/dlang/phobos/pull/8474