Bug 10978 – Better support of emplace for structs with immutable members

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-06T01:51:44Z
Last change time
2020-03-21T03:56:33Z
Assigned to
monarchdodra
Creator
monarchdodra

Comments

Comment #0 by monarchdodra — 2013-09-06T01:51:44Z
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 by b2.temp — 2017-09-14T09:54:11Z
The test case works nowadays.