[Issue 22614] New: Wrong copy constructor is called depending on context

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Dec 20 20:50:53 UTC 2021


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

          Issue ID: 22614
           Summary: Wrong copy constructor is called depending on context
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: stanislav.blinov at gmail.com

@safe // <- comment this @safe, and both asserts pass
unittest
{
    static struct S
    {
        int i;
        this(int i) { this.i = i; }
        this(ref const S) { i = 2; }
        this(ref S) immutable { i = 3; }
    }

    auto source = S(1);
    auto implicit = source;
    S explicit;
    explicit.__ctor(source);
    assert(implicit.i == 2);
    assert(explicit.i == 2);
}


This is blocking implementation of dup/idup for arrays that would correctly
support copy constructors.

(The unittest is actually adapted from existing one in druntime).

--


More information about the Digitalmars-d-bugs mailing list