Bug 24465 – Tuple does not get a copy constructor when its members need it
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-03-28T21:06:11Z
Last change time
2024-04-01T22:02:38Z
Keywords
pull
Assigned to
No Owner
Creator
Jonathan M Davis
Comments
Comment #0 by issues.dlang — 2024-03-28T21:06:11Z
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.
Comment #1 by dlang-bot — 2024-03-29T01:54:06Z
@jmdavis created dlang/phobos pull request #8963 "Fix bugzilla #24465: Make Tuple work with copy constructors" fixing this issue:
- Fix bugzilla #24465: Make Tuple work with copy constructors
If there's a constructor that looks like a copy constructor except that
it takes an rvalue instead of taking the argument by ref, then that type
can't have a copy constructor, and one of Tuple's constructors was
causing that problem. So, this fixes it so that it doesn't.
https://github.com/dlang/phobos/pull/8963
Comment #2 by dlang-bot — 2024-04-01T18:15:31Z
dlang/phobos pull request #8963 "Fix bugzilla #24465: Make Tuple work with copy constructors" was merged into stable:
- 7b1bc06f724763a4a38e5390485b77a6d95b176c by Jonathan M Davis:
Fix bugzilla #24465: Make Tuple work with copy constructors
If there's a constructor that looks like a copy constructor except that
it takes an rvalue instead of taking the argument by ref, then that type
can't have a copy constructor, and one of Tuple's constructors was
causing that problem. So, this fixes it so that it doesn't.
https://github.com/dlang/phobos/pull/8963
Comment #3 by dlang-bot — 2024-04-01T22:02:38Z
dlang/phobos pull request #8966 "merge stable" was merged into master:
- 7858069343679401fea49a48bcaf965b7f22dde0 by Jonathan M Davis:
Fix bugzilla #24465: Make Tuple work with copy constructors
If there's a constructor that looks like a copy constructor except that
it takes an rvalue instead of taking the argument by ref, then that type
can't have a copy constructor, and one of Tuple's constructors was
causing that problem. So, this fixes it so that it doesn't.
https://github.com/dlang/phobos/pull/8966