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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jul 1 09:30:08 PDT 2016


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

          Issue ID: 16224
           Summary: -cov marks the last line of do/while(0); as uncovered
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: andrei at erdani.com

Consider:

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

unittest
{
    fun(0);
    fun(1);
    fun(2);
}

The do/while(0); idiom is a trick used to avoid goto or additional state
variables. It simply allows code to jump to a common point by using "break".
The coverage analyzer marks the line with "while (0);" as uncovered, although
that is an useless tidbit.

--


More information about the Digitalmars-d-bugs mailing list