Bug 4521 – Array-wise assignment on unallocated array is accepted
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-07-27T11:46:00Z
Last change time
2010-07-28T10:35:55Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2010-07-27T11:46:44Z
The following code should raise an out of bounds error:
import std.stdio;
void main() {
double[] c;
c[] = 4;
}
Comment #1 by nfxjfg — 2010-07-27T22:37:00Z
Maybe I'm missing something, but no it should not.
"c[] = 4;" just sets every array element to 4, and it works even if there are 0 array elements.
Comment #2 by clugdbug — 2010-07-27T23:57:22Z
(In reply to comment #1)
> Maybe I'm missing something, but no it should not.
> "c[] = 4;" just sets every array element to 4, and it works even if there are 0
> array elements.
Yes. Some related situations are definitely bugs though. Perhaps this one should be marked as a duplicate of bug 2547.
Comment #3 by bearophile_hugs — 2010-07-28T04:19:38Z
This is not a bug, I think this can be closed.
Comment #4 by andrej.mitrovich — 2010-07-28T05:55:29Z
Comment #5 by andrej.mitrovich — 2010-07-28T06:38:07Z
Actually I think I'm confusing myself with how dynamic allocation works. I thought the dynamic array always have to be called with new, but it appears I can change the length of an array without calling new in the first place, e.g.:
int[] a;
a.length = 4;
a[] = 4;
writeln(a); // writes 4 4 4 4
So this should probably get closed. Sorry for the confusion.