D-Scanner icon indicating copy to clipboard operation
D-Scanner copied to clipboard

False positive for Unmodified Variable

Open JackStouffer opened this issue 9 years ago • 5 comments

Consider the following code

    int opApply(scope int delegate(ref dchar) dg)
    {
        int result = 0;
        while (s.length != 0)
        {
            dchar c = decode(s);
            result = dg(c);
            if (result != 0) break;
        }
        return result;
    }

dscanner gives this warning:

std/encoding.d(585:19)[warn]: Variable c is never modified and could have been declared const or immutable.

dscanner should not emit this because the function called requires a ref parameter.

JackStouffer avatar Jul 19 '16 18:07 JackStouffer

Another typical case:

bool foo() {
	…
	bool overflowed;
	significand = mulu(significand, pow, overflowed);
	if (overflowed)
		return false;
}

Here overflowed is passed by mutable ref and it must be assumed that it gets modified.

mleise avatar Oct 20 '18 20:10 mleise

D-Scanner doesn't know mulu signature.

ghost avatar Oct 20 '18 21:10 ghost

Because it only sees the current module?

mleise avatar Oct 21 '18 03:10 mleise

Yes. And this limitation is unlikely to fall.

ghost avatar Oct 21 '18 11:10 ghost

This too.

import std.stdio;
import std.format;
void main() {
    float value;
    string input = readln();
    input.formattedRead!"%f"(value);
}

buckle2000 avatar Apr 18 '20 15:04 buckle2000