dchar undefined behaviour

Vladimir Panteleev via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 23 14:22:36 PDT 2015


On Friday, 23 October 2015 at 01:31:47 UTC, tsbockman wrote:
> dchar c = cast(dchar) uint.max;
> if(c > 0x10FFFF)
>     writeln("invalid");
> else
>     writeln("OK");
>
> With constant folding for integer comparisons, the above will 
> print "OK" rather than "invalid", as it should. The predicate 
> (c > 0x10FFFF) is simply *assumed* to be false, because the 
> current starting range.imax for a dchar expression is dchar.max.

That doesn't sound right. In fact, this puts into question why 
dchar.max is at the value it is now. It might be the current 
maximum at the current version of Unicode, but this seems like a 
completely pointless restriction that breaks 
forward-compatibility with future Unicode versions, meaning that 
D programs compiled today may be unable to work with Unicode text 
in the future because of a pointless artificial limitation.



More information about the Digitalmars-d mailing list