D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10978 - Better support of emplace for structs with immutable members
Summary: Better support of emplace for structs with immutable members
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: monarchdodra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-06 01:51 UTC by monarchdodra
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description monarchdodra 2013-09-06 01:51:44 UTC
emplace was recetly improved to (better) support structs that have immutable members.

Implementation-wise, it was actually "lucky" it worked (code wasn't written to explicitly support it), and generated runtime that does it is sub-optimal (calls to memcpy when an assignment would be enough, calls to tid.postblit that aren't actually necessary.). Details.

More importantly though, support is "flakey" in the sense that "postblit" initialization will work (S to S), but aggregate initialization will fail.

//----
import std.conv;

struct S
{
    immutable int i;
}

void main()
{
    S s = void;
    emplace(&s, S(1)); //Fails 2.063.2; Passes 2.064ALPHA
    emplace(&s, 1); //Fails on both 2.063.2 and 2.064ALPHA
}
//----

So, in 2.064ALPHA, while "emplace(&s, S(1));" will work, "emplace(&s, 1);" will not. This is inconsistent, and emplace should be fixed to support it.
Comment 1 basile-z 2017-09-14 09:54:11 UTC
The test case works nowadays.