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: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Andrej Mitrovic <[email protected]> 2013-06-30
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.d
> core.exception.AssertError@test(11): Assertion failure
The 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.d
> object.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: -------