[Issue 1339] Invariant/const-ness is broken by built-in array properties
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 19 01:27:03 PST 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1339
------- Comment #4 from 2korden at gmail.com 2009-02-19 03:27 -------
(In reply to comment #3)
> It reallocated array on increasing length. Seems valid.
>
Yes, the length part is fine. Here is slightly modified test case:
import std.stdio;
import std.algorithm;
void main()
{
immutable(int)[] x = [1, 5, 3, 4];
auto y = x;
writefln(y);
x.sort;
writefln(y); // immutable variable is modified!
x.reverse;
writefln(y);
}
Problem is that sort and reverse work in-place, thus modifying immutable
variable. It should either not compile /or/ allocate a copy. I don't like the
hidden allocations, so this should be just disallowed, imo.
--
More information about the Digitalmars-d-bugs
mailing list