Bug 6000 – Value range propagation does not work with modulus (%) with a constant

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-05-14T08:05:00Z
Last change time
2011-06-12T11:06:25Z
Keywords
rejects-valid
Assigned to
nobody
Creator
kennytm

Comments

Comment #0 by kennytm — 2011-05-14T08:05:03Z
Test case: --------------------------------- void main() { ulong t; uint v = t & 15; // ok uint u = t % 16; // error? } --------------------------------- x.d(4): Error: cannot implicitly convert expression (t % 16LU) of type ulong to uint --------------------------------- There should not be error. The range of "t % 16" is entirely within [0, 15] which is inside an "uint". (See also bug 3147)
Comment #1 by bearophile_hugs — 2011-05-17T02:51:59Z
A similar case: void main() { long n = 10520; ubyte b = n % 10; }
Comment #2 by kennytm — 2011-06-12T11:06:25Z
*** This issue has been marked as a duplicate of issue 3147 ***