D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17978 - coercion from int to ubyte wrongly accepted
Summary: coercion from int to ubyte wrongly accepted
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 regression
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2017-11-11 14:39 UTC by Puneet Goel
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Puneet Goel 2017-11-11 14:39:26 UTC
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 Puneet Goel 2017-11-11 14:40:22 UTC
>> 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 Walter Bright 2018-12-16 11:18:36 UTC
Why is this marked as a regression?
Comment 3 Walter Bright 2019-12-18 05:25:21 UTC
It's not an error because, by the magic of VRP (Value Range Propagation) no bits are lost.