Bug 6585 – std.variant cannot handle shared arrays

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-08-31T18:39:54Z
Last change time
2017-08-22T18:04:38Z
Assigned to
No Owner
Creator
David Nadlinger
See also
https://issues.dlang.org/show_bug.cgi?id=5538, https://issues.dlang.org/show_bug.cgi?id=13262

Comments

Comment #0 by code — 2011-08-31T18:39:54Z
As discovered during the review for Jonas Drewson's libcurl wrapper, std.concurrency (correctly, according to TDPL) accepts shared arrays, but cannot handle them internally: --- import std.concurrency; void main() { auto tid = spawn(function(){}); send(tid, cast(shared(int)[])null); } --- --- std/variant.d(529): Error: function core.stdc.string.memcpy (void* s1, in const(void*) s2, uint n) is not callable using argument types (ubyte[32u]*,shared(int)*,uint) std/variant.d(529): Error: cannot implicitly convert expression (& rhs) of type shared(int)* to const(void*) --- From the error message, the problem seems std.variant trying to copy a shared(int) to another in its opIndex implementation using memcpy(&target, &source, source.sizeof). This fails because shared(int)* isn't implicitly convertible to const(void*). The issue can also be demonstrated by the following example directly using std.variant: --- import std.variant; void main() { shared(int)[] array; auto v = Variant(array); } ---
Comment #1 by dlang.element126 — 2014-04-22T21:31:32Z
This bug is still present in Phobos 2.065.0. See: http://dpaste.dzfl.pl/79743d502b27 As pointed out by David, this seems to be caused by Variant trying to pass a shared(double)* to the C function stdc.string.memcpy (btw, it is not specific to double). The error message has now become more cryptic. The same test case for Variant (http://dpaste.dzfl.pl/e0dcfdf241bb) now gives (truncated output for DMD): --- /usr/include/dlang/dmd/std/variant.d(585): Error: function core.stdc.string.memcpy (void* s1, const(void*) s2, ulong n) is not callable using argument types (ubyte[32]*, shared(double)*, ulong) /usr/include/dlang/dmd/std/variant.d(427): Error: template instance std.variant.VariantN!(32LU).VariantN.opAssign!(shared(double)) error instantiating ---
Comment #2 by dfj1esp02 — 2016-08-05T13:15:31Z
Also affected shared and immutable AAs. Ideally Variant should be covered for supported types and their shared and immutable variants.
Comment #3 by dfj1esp02 — 2017-08-22T16:16:57Z
std.concurrency problem is fixed in issue 13262, though don't know if it applies to all uses of variant.
Comment #4 by schveiguy — 2017-08-22T18:04:38Z
Should be fixed by PR in 13262. Almost the exact code in the OP's comment is now in a unit test: https://github.com/dlang/phobos/blob/752fc0323a92d37056bb373cf8b91885a6406320/std/variant.d#L1390 *** This issue has been marked as a duplicate of issue 13262 ***