This seems like what could be a common cause of bugs

Steven Schveighoffer schveiguy at yahoo.com
Tue Jul 12 08:10:08 PDT 2011


On Tue, 12 Jul 2011 11:07:57 -0400, Kagamin <spam at here.lot> wrote:

> Steven Schveighoffer Wrote:
>
>> Yes, but this is getting into territory where the false positive rate
>> might get high.
>
> I bet it will be difficult to find a real-world example of this false  
> positive.

It depends on how the warning is triggered.

Does this fail?

double x = 1;

Does this:

double x = 1 / 2;

How about this:

void foo(int x, int y)
in
{
    assert(y != 0);
    assert(x % y == 0);
}
body
{
   double z = x / y;
}

The reason for declaring something a double is not always because you want  
the thing you are assigning it to be a double expression.  For instance,  
sometimes I do something like this:

int z = x / y;

And then realize, all the places where I use z, I actually want to be  
doubles, so I simply change it to:

double z = x / y;

To avoid frequent casting.

-Steve


More information about the Digitalmars-d-learn mailing list