www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19904] New: move semantics fail through the `emplace` pipeline

https://issues.dlang.org/show_bug.cgi?id=19904

          Issue ID: 19904
           Summary: move semantics fail through the `emplace` pipeline
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: turkeyman gmail.com

Consider the emplace function:

T* emplace(T, Args...)(T* chunk, auto ref Args args)
    if (is(T == struct) || Args.length == 1)
{
    import core.internal.lifetime : emplaceRef;

    emplaceRef!T(*chunk, args);
    return chunk;
}


Note there is no `forward!args` then it is passed to `emplaceRef`. This causes
the arguments to be unnecessarily copied, potentially executing a bunch of copy
code.

Now looking into `emplaceRef` (which I won't paste here because it's a
monster!), you'll see many calls to:
  p.__ctor(args);

Note a similar lack of `forward!args` at all the constructor calls, which leads
to a second layer of unnecessary copying.

TL;DR, move semantics in D are woefully broken!

--
May 26 2019