Why is this not a warning?

Shachar Shemesh via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 16 09:40:49 PDT 2016


Please consider the following program, which is a reduced version of a 
problem I've spent the entire of today trying to debug:

import std.stdio;

void main() {
     enum ulong MAX_VAL = 256;
     long value = -500;

     if( value>MAX_VAL )
         value = MAX_VAL;

     writeln(value);
}

People who are marginally familiar with integer promotion will not be 
surprised to know that the program prints "256". What is surprising to 
me is that this produced neither error nor warning.

The comparable program in C++, when compiled with gcc, correctly warns 
about signed/unsigned comparison (though, to be fair, it seems that 
clang doesn't).


More information about the Digitalmars-d mailing list