Bug 256 – Implicit unsigned to signed doesn't always work.

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-07-17T14:59:11Z
Last change time
2019-08-06T21:22:28Z
Keywords
rejects-valid
Assigned to
Walter Bright
Creator
James Pelcis

Comments

Comment #0 by jpelcis — 2006-07-17T14:59:11Z
According to the D spec, a signed type can be implicitly converted to its equivalent unsigned type (see Types, Implicit Conversions). Testing shows that that isn't always true. --------------------------- void main () { ubyte byteValue = cast(byte)-1; ushort shortValue = cast(short)-1; uint intValue = cast(int)-1; ulong longValue = cast(long)-1; } --------------------------- C:\programs>dmd test.d test.d(2): cannot implicitly convert expression (cast(byte)-1) of type byte to u byte test.d(3): cannot implicitly convert expression (cast(short)-1) of type short to ushort --------------------------- As you can see, only the uint and ulong parts can be successfully compiled. Casting explicitly to unsigned type still works.
Comment #1 by bugzilla — 2006-08-11T19:14:24Z
Fixed DMD 0.164 (revised documentation to reflect intended behavior)
Comment #2 by dlang-bot — 2019-08-06T21:22:28Z
dlang-community/dfmt pull request #446 "Fix: Issue 256 "named member struct initialisers"" was merged into master: - ac61efe7670acfa06cee2edaf61d4f7c368e4ce7 by sobaya: Fix: Issue 256 "named member struct initialisers" - 1024f167154aa37e754fa46abad84a528ea9f99e by sobaya: Add: struct fields to the test of issue 256 https://github.com/dlang-community/dfmt/pull/446