[Issue 12589] New: std.random.randomCover fails for empty ranges

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 16 08:15:03 PDT 2014


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

          Issue ID: 12589
           Summary: std.random.randomCover fails for empty ranges
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: jens.k.mueller at gmx.de

The following code fails (the second assert does not hold).

unittest                                                                        
{                                                                               
    import std.random;                                                          
    int[] r = [];                                                               
    auto gen = Random(0);                                                       
    auto c = randomCover(r, gen);                                               
    assert(c.length == 0);                                                      
    assert(c.empty);                                                            
}

Since empty is false calling front is valid which leads to disaster.

I used DMD64 D Compiler v2.065 on Linux.

--


More information about the Digitalmars-d-bugs mailing list