[Issue 16224] -cov marks the last line of do/while(0); as uncovered

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jul 1 10:48:43 PDT 2016


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

--- Comment #3 from Andrei Alexandrescu <andrei at erdani.com> ---
For clarity, I'll paste the code (fixed to do something useful, i.e. compute
the cube of an int) and the listing:

int cube(int x)
{
    do
    {
        if (x == 0)
            break;
        if (x == 1)
            break;
        if (x == -1)
            break;
        return x * x * x;
    }
    while (0);
    return x;
}

unittest
{
    cube(0);
    cube(1);
    cube(-1);
    cube(2);
}

=================================

       |int cube(int x)
       |{
       |    do
       |    {
      4|        if (x == 0)
      1|            break;
      3|        if (x == 1)
      1|            break;
      2|        if (x == -1)
      1|            break;
      1|        return x * x * x;
       |    }
0000000|    while (0);
      3|    return x;
       |}
       |
       |unittest
       |{
      1|    cube(0);
      1|    cube(1);
      1|    cube(-1);
      1|    cube(2);
       |}

--


More information about the Digitalmars-d-bugs mailing list