[Issue 20708] New: result of cast not specified when value is out of range

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 29 15:00:39 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20708

          Issue ID: 20708
           Summary: result of cast not specified when value is out of
                    range
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: johanengelen at weka.io

The specification says nothing about what the result of a numeric cast is when
the value is outside the receiving type's range.

For example:
```
uint a = 260;
auto b = cast(ubyte) a;

float f = 1.203125f  * 255.0f;
auto zz =  cast(ubyte) f;
```

Not having the result specified currently means that it is treated as UB by LDC
and GDC.

--


More information about the Digitalmars-d-bugs mailing list