[Issue 22271] Appending to an empty array reallocate
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Sep 3 23:44:43 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22271
--- Comment #7 from deadalnix <deadalnix at gmail.com> ---
(In reply to Vladimir Panteleev from comment #6)
> It would be a breaking change.
>
> ///////////// test.d /////////////
> string fun() @safe
> {
> immutable char[3] arr = "foo";
> string s = arr[];
> string r;
> r ~= s;
> return r;
> }
> //////////////////////////////////
I don't think this is a reasonable expectation that there is duplication here.
If you want it heap allocated, you ought to call dup/idup.
After all, it does it the other way around:
> string fun(string stuff)
> {
> immutable char[3] arr = "foo";
> string s = arr[];
> return s ~ stuff;
> }
This is all good and well, until stuff is an empty array, in which case it is
not anymore.
--
More information about the Digitalmars-d-bugs
mailing list