Bug 8759 – autogenerated opEquals does no handle well Variant
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-04T14:40:00Z
Last change time
2014-04-24T18:55:42Z
Assigned to
nobody
Creator
fawzi
Comments
Comment #0 by fawzi — 2012-10-04T14:40:00Z
Not sure where to put this (if it is a phobos or dmd bug), but the interaction is ugly: adding the field a (or any field that has opEquals with const) to struct B makes the compilation fail with the given error.
Manually implementing a const opEquals with casts is a workaround for this, but I find it ugly because a small change to a (adding opEquals), requires opEquals to struct using it.
-----------
module t;
import std.variant;
struct A{
int opEquals(ref const(A) o) const /+ this const is the trigger of the bug +/ {
return &o is &this;
}
}
struct B{
Variant x;
A a;
}
------------
fails compiling with dmd 2.060 with:
/home/fawzi/d/dmd2/linux/bin64/../../src/phobos/std/variant.d(513): Error: static assert "Assigning Variant objects from const Variant objects is currently not supported."
/home/fawzi/d/dmd2/linux/bin64/../../src/phobos/std/variant.d(495): instantiated from here: opAssign!(const(VariantN!(32LU)))
/home/fawzi/d/dmd2/linux/bin64/../../src/phobos/std/variant.d(768): instantiated from here: __ctor!(const(VariantN!(32LU)))
t.d(10): instantiated from here: opEquals!(const(VariantN!(32LU)))
-----------
might be or be related with issue5310 or issue8328
Comment #1 by andrej.mitrovich — 2014-04-24T18:55:42Z