fix #380, templated enum seen as unused variable

This commit is contained in:
Basile Burg 2016-12-21 21:16:42 +01:00
parent f283650c12
commit 15b86bf159
No known key found for this signature in database
GPG Key ID: 1868039F415CB8CF
1 changed files with 22 additions and 4 deletions

View File

@ -10,7 +10,7 @@ import analysis.base;
import std.container;
import std.regex : Regex, regex, matchAll;
import dsymbol.scope_ : Scope;
import std.algorithm : map;
import std.algorithm.iteration : map;
/**
* Checks for unused variables.
@ -207,10 +207,14 @@ class UnusedVariableCheck : BaseAnalyzer
{
if (interestDepth > 0)
{
if (primary.identifierOrTemplateInstance !is null
&& primary.identifierOrTemplateInstance.identifier != tok!"")
const IdentifierOrTemplateInstance idt = primary.identifierOrTemplateInstance;
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"
|| primary.primary == tok!"wstringLiteral"
@ -430,6 +434,20 @@ unittest
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.
{
return a;