www.digitalmars.com         C & C++   DMDScript  

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

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 puremagic.com
          Reporter: andrei 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.

--
Jul 01 2016