fix #380, templated enum seen as unused variable
This commit is contained in:
parent
f283650c12
commit
15b86bf159
|
@ -10,7 +10,7 @@ import analysis.base;
|
||||||
import std.container;
|
import std.container;
|
||||||
import std.regex : Regex, regex, matchAll;
|
import std.regex : Regex, regex, matchAll;
|
||||||
import dsymbol.scope_ : Scope;
|
import dsymbol.scope_ : Scope;
|
||||||
import std.algorithm : map;
|
import std.algorithm.iteration : map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for unused variables.
|
* Checks for unused variables.
|
||||||
|
@ -207,10 +207,14 @@ class UnusedVariableCheck : BaseAnalyzer
|
||||||
{
|
{
|
||||||
if (interestDepth > 0)
|
if (interestDepth > 0)
|
||||||
{
|
{
|
||||||
if (primary.identifierOrTemplateInstance !is null
|
const IdentifierOrTemplateInstance idt = primary.identifierOrTemplateInstance;
|
||||||
&& primary.identifierOrTemplateInstance.identifier != tok!"")
|
|
||||||
|
if (idt !is null)
|
||||||
{
|
{
|
||||||
variableUsed(primary.identifierOrTemplateInstance.identifier.text);
|
if (idt.identifier != tok!"")
|
||||||
|
variableUsed(idt.identifier.text);
|
||||||
|
else if (idt.templateInstance && idt.templateInstance.identifier != tok!"")
|
||||||
|
variableUsed(idt.templateInstance.identifier.text);
|
||||||
}
|
}
|
||||||
if (mixinDepth > 0 && primary.primary == tok!"stringLiteral"
|
if (mixinDepth > 0 && primary.primary == tok!"stringLiteral"
|
||||||
|| primary.primary == tok!"wstringLiteral"
|
|| primary.primary == tok!"wstringLiteral"
|
||||||
|
@ -430,6 +434,20 @@ unittest
|
||||||
int a; // [warn]: Variable a is never used.
|
int a; // [warn]: Variable a is never used.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue 380
|
||||||
|
int templatedEnum()
|
||||||
|
{
|
||||||
|
enum a(T) = T.init;
|
||||||
|
return a!int;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issue 380
|
||||||
|
int otherTemplatedEnum()
|
||||||
|
{
|
||||||
|
auto a(T) = T.init; // [warn]: Variable a is never used.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void doStuff(int a, int b) // [warn]: Parameter b is never used.
|
void doStuff(int a, int b) // [warn]: Parameter b is never used.
|
||||||
{
|
{
|
||||||
return a;
|
return a;
|
||||||
|
|
Loading…
Reference in New Issue