[Issue 10516] Array length is not checked when array is a manifest constant
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jun 30 19:01:19 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10516
Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
--- Comment #1 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-06-30 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.d
> > object.Error: lengths don't match for array copy, 5 = 4
Actually 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.d
> core.exception.AssertError at test(5): Assertion failure
I 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: -------
More information about the Digitalmars-d-bugs
mailing list