Skip to content

Commit

Permalink
Fix issue 17803 std.typecons.Tuple: opAssign should return ref Tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
Biotronic committed Sep 7, 2017
1 parent f650d62 commit ba2a1ce
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion std/typecons.d
Expand Up @@ -847,7 +847,7 @@ template Tuple(Specs...)
* source `Tuple` must be implicitly assignable to each
* respective element of the target `Tuple`.
*/
void opAssign(R)(auto ref R rhs)
ref Tuple opAssign(R)(auto ref R rhs)
if (areCompatibleTuples!(typeof(this), R, "="))
{
import std.algorithm.mutation : swap;
Expand All @@ -870,6 +870,7 @@ template Tuple(Specs...)
// Do not swap; opAssign should be called on the fields.
field[] = rhs.field[];
}
return this;
}

/**
Expand Down Expand Up @@ -1802,6 +1803,22 @@ private template ReverseTupleSpecs(T...)
);
}

// Issue 17803, parte uno
@safe unittest
{
auto a = tuple(3, "foo");
assert(__traits(compiles, { a = (a = a); }));
}
// Ditto
@safe unittest
{
Tuple!(int[]) a, b, c;
a = tuple([0, 1, 2]);
c = b = a;
assert(a[0].length == b[0].length && b[0].length == c[0].length);
assert(a[0].ptr == b[0].ptr && b[0].ptr == c[0].ptr);
}

/**
Constructs a $(LREF Tuple) object instantiated and initialized according to
the given arguments.
Expand Down

0 comments on commit ba2a1ce

Please sign in to comment.