www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22614] New: Wrong copy constructor is called depending on

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 puremagic.com
          Reporter: stanislav.blinov 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).

--
Dec 20 2021