[Issue 259] Comparing signed to unsigned does not generate an error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 8 07:21:30 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=259



--- Comment #39 from Andrei Alexandrescu <andrei at erdani.com> 2013-04-08 07:21:23 PDT ---
Thanks Lionello for taking this over. I thought of one more case this morning
so let me insert in the food chain:

(Recall a is signed and b is unsigned.)

==============

1. If a.sizeof > b.sizeof, then a < b is lowered into a < cast(typeof(a)) b.
Then signed comparison proceeds normally. This is a classic value-based
conversion dating from the C days, and we do it in D as well.

2. Otherwise, if a is determined through Value Range Propagation to be greater
than or equal to zero, then a < b is lowered into cast(U) a < b, where U is the
unsigned variant of typeof(a). Then unsigned comparison proceeds normally.

3. (NEW) Otherwise, if b is determined through Value Range Propagation to be
less than or equal to typeof(b).max / 2, then a < b is lowered into a < cast(S)
b, where S is the signed variant of typeof(b). Then signed comparison proceeds
normally.

4. Otherwise, the comparison is in error. The error message may recommend using
the std.traits.unsigned function, which executes a size-informed cast.

==============

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list