reasoning of evaluating code after return in current block (static if return)

bastien penavayre via Digitalmars-d digitalmars-d at puremagic.com
Sun May 7 15:34:14 PDT 2017


Hi something's been bugging me for a while,
for the following code:

{
    auto t = tuple(0,0);
    return true;
    auto v = t[5];
    return false;
}

Why is the code following "return true" evaluated ? I know that 
it's the same
with the C++ but I was wondering why ?
My guess is for goto/labels but I find odd to evaluate it by 
default.
Furthermore one of my issues with this is that it has a negative 
impact on "static if" and make it cumbersome in some situations.

For instance this snippet comming from 
"https://github.com/uncrustify/uncrustify/issues/252"

ClLinearExpression opBinary(string op) (double constant)
{
static if (op == "+")
             return new ClLinearExpression(this, 1, constant);
         else
             static if (op == "-")
                 return new ClLinearExpression(this, 1, -constant);
             else
                 static if (op == "*")
                     return new ClLinearExpression(this, constant, 
0);
                 else
                     static if (op == "/")
                         return new ClLinearExpression(this, 1.0 / 
constant, 0);
     }


More information about the Digitalmars-d mailing list