digitalmars.D.bugs - [Issue 10516] New: Array length is not checked when array is a manifest constant
- d-bugmail puremagic.com (44/46) Jun 30 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10516
- d-bugmail puremagic.com (24/41) Jun 30 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10516
http://d.puremagic.com/issues/show_bug.cgi?id=10516 Summary: Array length is not checked when array is a manifest constant Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: andrej.mitrovich gmail.com 18:38:31 PDT --- ----- void main() { enum HexSize = 5; // note: smaller initializer count enum char[HexSize] srcHex = "1234"; char[HexSize] tgtHex = "12345"; // should error with: lengths don't match for array copy assert(tgtHex[0 .. 4] == srcHex); } ----- $ dmd test.dcore.exception.AssertError test(11): Assertion failureThe problem here is that the runtime allowed the left-hand side and right-hand side arrays to be compared even though their lengths do not match. If you convert the source array from a manifest constant into a regular array (by removing enum) then the error is proper: ----- void main() { enum HexSize = 5; // note: smaller initializer count /* enum */ char[HexSize] srcHex = "1234"; char[HexSize] tgtHex = "12345"; assert(tgtHex[0 .. 4] == srcHex); } ----- $ dmd test.dobject.Error: lengths don't match for array copy, 5 = 4-- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 30 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10516 Andrej Mitrovic <andrej.mitrovich gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID 19:01:18 PDT -------- void main() { enum HexSize = 5; // note: smaller initializer count /* enum */ char[HexSize] srcHex = "1234"; char[HexSize] tgtHex = "12345"; assert(tgtHex[0 .. 4] == srcHex); } ----- $ dmd test.dActually this test-case is invalid because the error is thrown in the initializer line, not the comparison line. And another thing I just realized is that it's perfectly ok to compare static arrays of non-matching sizes, which makes the whole report invalid.. but I don't understand why this is allowed: void main() { char[5] srcHex = "12345"; char[3] tgtHex = "123"; assert(srcHex == tgtHex); } $ dmd test.dobject.Error: lengths don't match for array copy, 5 = 4core.exception.AssertError test(5): Assertion failureI would have hoped to get a length mismatch error, or even a compile-time error. Oh well.. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 30 2013