[Issue 16131] New: A struct is being copied unnecessarily when initialized

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jun 6 02:35:53 PDT 2016


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

          Issue ID: 16131
           Summary: A struct is being copied unnecessarily when
                    initialized
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: eyal at weka.io

Even when the struct disallows copying, it is being temporarily created and
copied. This reproduces on both dmd and ldc2.

Reproducing example:

struct Foo {
    @disable this(this);
    this(out Foo *x) { x = &this; }
}

void main() {
    Foo *x;
    auto a = Foo(x);
    assert(x == &a); // OK
    Foo b;
    b = Foo(x);
    assert(x == &b); // FAILS
}

--


More information about the Digitalmars-d-bugs mailing list