[Issue 12944] New: std.variant does not observe value semantics for large value types.
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Jun 18 18:30:17 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12944
Issue ID: 12944
Summary: std.variant does not observe value semantics for large
value types.
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: Phobos
Assignee: nobody at puremagic.com
Reporter: opantm2+dbugs at gmail.com
Assigning a Variant to another Variant which contains a large value type causes
both Variants to have a reference to the same value. Currently this is not a
huge issue because the only way to modify the Variant's reference to a large
value type (that is, larger than Variant.size which is 32 bytes on x64), is
through the use of peek on a struct. This will become a larger issue when
std.variant supports static arrays however.
Sample:
import std.variant;
struct Foo {
int foo;
ubyte[32] padding;
}
void main() {
Foo f;
f.foo = 3;
Variant v = f;
Variant v2 = v;
auto fp = v.peek!Foo;
fp.foo = 6;
assert(v2.get!Foo.foo == 3); // fails
}
Commenting out the padding makes this work as expected.
--
More information about the Digitalmars-d-bugs
mailing list