Bug 11416 – Array and slice assignment causes garbage values
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-01T18:56:00Z
Last change time
2015-06-09T01:31:17Z
Keywords
wrong-code
Assigned to
nobody
Creator
daniel350
Comments
Comment #0 by daniel350 — 2013-11-01T18:56:54Z
void main() {
float[3] x = [1,1,1];
float[] y = [4,4,4,4];
float[5] w = x[] + y[]; //ok
writeln(w); // [5, 5, 5, 4, 5.60519e-45]
}
w should be [5, 5, 5, 4, float.init]
Right?
http://dpaste.dzfl.pl/fork/53b6d5b5
Comment #1 by monarchdodra — 2013-11-02T02:55:56Z
> x[] + y[]; //ok
First: This is already wrong, and should lead to an Error from druntime. Unfortunalty, since druntime is compiled in release mode, you don't trigger it: http://d.puremagic.com/issues/show_bug.cgi?id=8650
Second: "float[5] w = ..." well... ditto. If the array lengths don't match, it's wrong behavior.
Conclusion: The program is wrong, but since druntime is in release, you don't get an error, so you see undefined behavior.
It would have been nice if it had errored out, but didn't. You can always try it re-compiling druntime in non-release: you'll see it error.
Changing this to ER: Should throw an error, or should be able to chose non-release druntime by default.
Comment #2 by daniel350 — 2013-11-02T20:03:44Z
The correctness of the language shouldn't be reliant on the runtime...
Comment #3 by verylonglogin.reg — 2013-11-07T12:56:59Z
(In reply to comment #0)
> Right?
Wrong. The runtime must throw in such cases. Currently it doesn't because of Issue 8650.
Comment #4 by yebblies — 2013-11-14T21:38:49Z
*** This issue has been marked as a duplicate of issue 2547 ***