fix #352 - False positive: Parameter is never used, pointers

This commit is contained in:
Basile Burg 2017-05-08 15:39:01 +02:00
parent b2d96ad777
commit 004847624b
No known key found for this signature in database
GPG Key ID: 1868039F415CB8CF
1 changed files with 25 additions and 6 deletions

View File

@ -300,16 +300,23 @@ class UnusedVariableCheck : BaseAnalyzer
override void visit(const Parameter parameter)
{
import std.algorithm : canFind;
import std.algorithm.iteration : filter;
import std.range : empty;
import std.array : array;
if (parameter.name != tok!"")
{
immutable bool isRef = canFind(parameter.parameterAttributes, cast(IdType) tok!"ref")
|| canFind(parameter.parameterAttributes,
cast(IdType) tok!"in") || canFind(parameter.parameterAttributes,
cast(IdType) tok!"out");
immutable bool isRef =
canFind(parameter.parameterAttributes, cast(IdType) tok!"ref") ||
canFind(parameter.parameterAttributes, cast(IdType) tok!"in") ||
canFind(parameter.parameterAttributes, cast(IdType) tok!"out");
immutable bool isPtr = parameter.type && !parameter.type
.typeSuffixes.filter!(a => a.star != tok!"").empty;
variableDeclared(parameter.name.text, parameter.name.line,
parameter.name.column, true, isRef);
parameter.name.column, true, isRef | isPtr);
if (parameter.default_ !is null)
{
interestDepth++;
@ -432,7 +439,7 @@ private:
Regex!char re;
}
unittest
@system unittest
{
import std.stdio : stderr;
import analysis.config : StaticAnalysisConfig, Check;
@ -489,6 +496,18 @@ unittest
a = 1;
}
// Issue 352
void test352_1()
{
void f(int *x) {*x = 1;}
}
void test352_2()
{
void f(Bat** bat) {*bat = bats.ptr + 8;}
}
}c, sac);
stderr.writeln("Unittest for UnusedVariableCheck passed.");
}