Not a compiler bug.

bachmeier no at
Thu Aug 13 10:06:47 UTC 2020

On Thursday, 13 August 2020 at 09:25:07 UTC, John Colvin wrote:

> Personally I would love to be able to disallow implicit 
> signed-to-unsigned conversions in almost all cases, but that 
> would be a big breaking change.

This was broken without even an announcement or discussion (maybe 
I missed it):

foreach(int ii, val; [1, 2, 3, 4, 5]) {}

Upon compilation, you get a message

Deprecation: foreach: loop index implicitly converted from size_t 
to int

I had to go back and fix lots of previously working code, even 
though there was no reason at all that it would ever fail to work 
correctly. Then there is the move to safe by default. Surely if 
we can make those changes, we can change the behavior in this 
case. The output of this program is a serious WTF:

import std;
void main()
     foreach(int ii, val; [1, 2, 3, 4, 5]) {
     writeln(-5000/[1, 2, 3, 4].length);

More information about the Digitalmars-d mailing list