Array-wise assignment on unallocated array

Andrej Mitrovic andrej.mitrovich at gmail.com
Tue Jul 27 11:47:32 PDT 2010


Thanks. Filed in bugzilla http://d.puremagic.com/issues/show_bug.cgi?id=4521

Walter Bright Wrote:

> Andrej Mitrovic wrote:
> > There's an example in TDPL showing array-wise expressions. I've modified the code and removed the allocation. This will compile and run without exceptions:
> > 
> > void main() {
> >     auto a = [0.5, -0.5, 1.5, 2];
> >     auto b = [3.5, 5.5, 4.5, -1];
> >     
> >     double[] c;
> >     c[] = (a[] + b[]) / 2;
> > }
> > 
> > I think assignments to unallocated arrays should throw a runtime exception, or at least give out a compile warning. Compare this to this code which throws a RangeError:
> > 
> > import std.stdio;
> > 
> > void main() {
> >     double[] c;
> >     c[0] = 4;
> > }
> > 
> > And the equivalent array-wise assignment which doesn't throw exceptions:
> > 
> > import std.stdio;
> > 
> > void main() {
> >     double[] c;
> >     c[] = 4;
> > }
> > 
> > Bugzilla-worthy?
> 
> Yes, it should throw an out of bounds error.



More information about the Digitalmars-d mailing list