Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion std/concurrency.d
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,17 @@ do

thisInfo.ident.mbox.get((T val) {
static if (T.length)
ret.field = val;
{
static if (isAssignable!T)
{
ret.field = val;
}
else
{
import core.lifetime : emplace;
emplace(&ret, val);
}
}
},
(LinkTerminated e) { throw e; },
(OwnerTerminated e) { throw e; },
Expand Down Expand Up @@ -2727,3 +2737,27 @@ auto ref initOnce(alias var)(lazy typeof(var) init, Mutex mutex)
receiveOnly!(bool);
assert(x[0] == 5);
}

// https://issues.dlang.org/show_bug.cgi?id=13930
@system unittest
{
immutable aa = ["0":0];
thisTid.send(aa);
receiveOnly!(immutable int[string]); // compile error
}

// https://issues.dlang.org/show_bug.cgi?id=19345
@system unittest
{
static struct Aggregate { const int a; const int[5] b; }
static void t1(Tid mainTid)
{
const sendMe = Aggregate(42, [1, 2, 3, 4, 5]);
mainTid.send(sendMe);
}

spawn(&t1, thisTid);
auto result1 = receiveOnly!(const Aggregate)();
immutable expected = Aggregate(42, [1, 2, 3, 4, 5]);
assert(result1 == expected);
}
10 changes: 9 additions & 1 deletion std/variant.d
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,15 @@ public:
{
alias UT = Unqual!T;
auto p = new UT;
*p = rhs;
static if (isAssignable!UT)
{
*p = rhs;
}
else
{
import core.lifetime : emplace;
emplace(p, rhs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, this requires the type UT to feature a constructor taking a T rhs lvalue argument, and should thus be equivalent to auto p = new UT(rhs). - I think that's not suited in general and should probably be replaced by a manual copy-emplace as used for the T.sizeof <= size case above. It cheats around immutability by faking a copy-construct, performing a bitcopy and invoking the postblit if necessary. By the looks of it, it currently seems to ignore copy ctors...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
memcpy(&store, &p, p.sizeof);
}
Expand Down