www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24465] New: Tuple does not get a copy constructor when its

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

          Issue ID: 24465
           Summary: Tuple does not get a copy constructor when its members
                    need it
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: issues.dlang jmdavisProg.com

An example:
---
import std.typecons;

void main()
{
    Tuple!(int, S) t;
    foo(t);
}

struct S
{
    int i;

    this(ref return scope inout(S) rhs) scope  trusted inout pure nothrow
    {
        this.i = rhs.i;
    }
}

void foo(Tuple!(int, S))
{
}
---

It fails with
---
bug.d(6): Error: function `foo` is not callable using argument types
`(Tuple!(int, S))`
bug.d(6):        `struct Tuple` does not define a copy constructor for
`Tuple!(int, S)` to `Tuple!(int, S)` copies
bug.d(19):        `bug.foo(Tuple!(int, S))` declared here
---

I _think_ that the problem is that this constructor
---
        this(U)(U another)
        if (areBuildCompatibleTuples!(typeof(this), U))
        {
            field[] = another.field[];
        }
---
is managing to serve as an rvalue constructor, which unfortunately, is
incompatible with copy constructors (I'm not convinced that it should be, but
it is). But regardless of what the exact reason that it's currently failing is,
it should work to create and copy Tuples which contain types with copy
constructors.

--
Mar 28