Wrong code gen / missing warning / my mistake?
Benjamin Thaut
code at benjamin-thaut.de
Mon Sep 10 10:08:29 PDT 2012
The following code
bool endsWith(string str, string end)
{
size_t to = str.length - end.length;
for(sizediff_t i = str.length - 1; i >= to; --i)
{
if(str[i] != end[i-to])
return false;
}
return true;
}
int main(string[] args)
{
return cast(int)endsWith("blub", "blub");
}
compiled with dmd 2.060 gives me a range violation. (with i = -1)
although it shouldn't. If I change to from size_t "to" sizediff_t
everything is fine. The comparison between the unsigned "to" and the
signed "i" is not done correctly.
Is this a code gen bug? Or is it missing a compiler warning / error? Or
is this entierly my fault?
Kind Regards
Benjamin Thaut
More information about the Digitalmars-d
mailing list