[Issue 2547] New: Array Ops should check length, at least when bounds checking is on
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 30 14:33:36 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2547
Summary: Array Ops should check length, at least when bounds
checking is on
Product: D
Version: 2.022
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: dsimcha at yahoo.com
import std.stdio;
void main() {
double[] foo = [1.0,2,3,4,5].dup;
double[] bar = [6.0,7,8,9,10].dup;
double[] baz = new double[1];
baz[] = foo[] + bar[];
writeln(baz); // Prints [7].
double[] waldo = new double[10]; // Should be all Nans.
waldo[] = foo[] + bar[];
writeln(waldo); // Prints [7 9 11 13 15 0 0 0 7 9].
double[] stuff = new double[10];
stuff[] = foo[] + waldo[];
writeln(stuff); // Prints [8 11 14 17 20 0 0 0 8 11].
}
The array ops should either automatically change the lengths of baz[] and
waldo[] to match foo[] and bar[] (both in release and debug mode), or throw a
RangeError when bounds checking is enabled.
In the last example, adding two arrays of different lengths either should not
be allowed and should throw a RangeError when bounds checking is enabled, or
should have reasonably well-defined behavior instead of the seemingly arbitrary
behavior exhibited.
--
More information about the Digitalmars-d-bugs
mailing list