www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24582] New: Detect unsafe casting to bool

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

          Issue ID: 24582
           Summary: Detect unsafe casting to bool
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: nick geany.org

Given that only 0 and 1 are safe values:
https://dlang.org/spec/function.html#safe-values

Each of the casts below should fail.

void main()  safe
{
    bool v = cast(bool) 2;

    ubyte[] a = [2, 4];
    auto b = cast(bool[]) a;
    auto c = cast(bool[]) [2, 4]; // literal cast
}

PR incoming.

--
Jun 03