This code causes an Internal Error
Sterling Christensen
sterlingchristensen at hotmail.com
Sat Jul 8 16:24:41 PDT 2006
// --- Begin test.d ---
uint octal (char[] s)
{
ubyte shift = (s.length - 1) * 3;
uint answer = 0;
for (int i = 0; i < s.length; i++)
{
answer += (s[i] - '0') << shift;
shift -= 3;
}
return answer;
}
void main ()
{
assert (octal("0777") == 0777);
}
// --- End of test.d ---
dmd -O test.d
Internal error: ../ztc/cgcod.c 1677
dmd v0.162
It compiles if you:
1. don't optimize (no -O)
2. change "return answer" to "return 0" on line 12
3. change the 3 on line 3 to 1, 2, 4, 7, or 8... 5, 6, 9, and 10 still
cause the internal error. (I didn't try higher than 10)
4. Change "ubyte shift" to "uint shift"
5. comment out the for or the answer+=
6. change the for to a foreach
More information about the Digitalmars-d-bugs
mailing list