Skip to content

Commit

Permalink
Fix Bugzilla Issue 24453 - idup fails for inout(T)[] slices
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke authored and adamdruppe committed Apr 13, 2024
1 parent 2d31d1a commit 45eb187
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions druntime/src/core/internal/array/duplication.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ U[] _dup(T, U)(scope T[] a) pure nothrow @trusted if (__traits(isPOD, T))
{
import core.stdc.string : memcpy;
import core.internal.array.construction: _d_newarrayUPureNothrow;
auto arr = _d_newarrayUPureNothrow!T(a.length, is(T == shared));
auto arr = _d_newarrayUPureNothrow!U(a.length, is(U == shared));
memcpy(cast(void*) arr.ptr, cast(const(void)*) a.ptr, T.sizeof * a.length);
return *cast(U[]*) &arr;
return arr;
}
}

Expand Down Expand Up @@ -358,3 +358,13 @@ U[] _dup(T, U)(T[] a) if (!__traits(isPOD, T))
static assert(test!Copy());
assert(test!Copy());
}

// https://issues.dlang.org/show_bug.cgi?id=24453
@safe unittest
{
static inout(char)[] foo(ref scope return inout(char)[] s)
{
auto bla = s.idup;
return s;
}
}

0 comments on commit 45eb187

Please sign in to comment.