www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20929] New: std.experimental.allocator.expandArray's

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

          Issue ID: 20929
           Summary: std.experimental.allocator.expandArray's range-based
                    overload fails to instantiate for char and wchar
                    arrays.
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: dbugreporter harrygillanders.com

If you call `expandArray` on a `char[]` or `wchar[]`, and provide a range from
which to expand the array with, it will fail to instantiate.

Such as with this test-case:

----
unittest
{
        import std.experimental.allocator : expandArray, makeArray,
theAllocator;
        import std.utf : byCodeUnit;

        char[] array = theAllocator.makeArray!char(0);

        theAllocator.expandArray(array, "foo".byCodeUnit());

        assert(array == "foo");
}
----

Which fails to compile with an error message like:

----
std\experimental\allocator\package.d(2228): Error: front(toFill) is not an
lvalue and cannot be modified
.\expand_array_bug.d(10): Error: template instance
std.experimental.allocator.expandArray!(char, RCIAllocator, ByCodeUnitImpl)
error instantiating
----


I've got a PR ready to fix this, which I'll submit after this bug report.

--
Jun 14 2020