Bug 17978 – coercion from int to ubyte wrongly accepted

Status
RESOLVED
Resolution
INVALID
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-11-11T14:39:26Z
Last change time
2020-03-21T03:56:31Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Puneet Goel

Comments

Comment #0 by puneet — 2017-11-11T14:39:26Z
With Github HEAD dmd I get: $ rdmd --force /tmp/test.d /tmp/test.d(3): Deprecation: integral promotion not done for ~foo, use '-transition=intpromote' switch or ~cast(int)(foo) /tmp/test.d(5): Deprecation: integral promotion not done for -foo, use '-transition=intpromote' switch or -cast(int)(foo) /tmp/test.d(6): Deprecation: integral promotion not done for -foo, use '-transition=intpromote' switch or -cast(int)(foo) To me it seems that line 5 should result in error since I am trying to coerce an int into a byte. void main() { // 1 byte foo; // 2 foo = ~foo; // 3 foo = ~cast(int) (foo); // 4 -- this should be an error but no foo = -foo; // 5 foo = cast(byte) (-foo); // 6 }
Comment #1 by puneet — 2017-11-11T14:40:22Z
>> To me it seems that line 5 should result in error since I am trying to coerce an int into a byte. I meant line 4.
Comment #2 by bugzilla — 2018-12-16T11:18:36Z
Why is this marked as a regression?
Comment #3 by bugzilla — 2019-12-18T05:25:21Z
It's not an error because, by the magic of VRP (Value Range Propagation) no bits are lost.