D-Scanner
D-Scanner copied to clipboard
False positive for Unmodified Variable
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.
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.
D-Scanner doesn't know mulu signature.
Because it only sees the current module?
Yes. And this limitation is unlikely to fall.
This too.
import std.stdio;
import std.format;
void main() {
float value;
string input = readln();
input.formattedRead!"%f"(value);
}