[Issue 18471] New: std.experimental.checkedint.Checked doesn't check on assignment or construction

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 19 21:32:59 UTC 2018


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

          Issue ID: 18471
           Summary: std.experimental.checkedint.Checked doesn't check on
                    assignment or construction
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: simen.kjaras at gmail.com

When constructing or assigning to a Checked!int with a custom hook that define
min and max, these min and max values are ignored.

import std.experimental.checkedint;

struct MyHook {
    enum min(T) = 3;
    enum max(T) = 15;

    static B onLowerBound(T, B)(T value, B bound)
    {
        assert(0);
    }

    static B onUpperBound(T, B)(T value, B bound)
    {
        assert(0);
    }
}

unittest
{
    // This should trigger one of the above asserts:
    Checked!(int, MyHook) a = 500;
    // As should this:
    a = 22;
    // Instead, Checked blithely ignores the limits, and this assert triggers:
    assert(a != 22);
}

--


More information about the Digitalmars-d-bugs mailing list