From 0afddd2c4ee09af5ebc8eaac6620ffd87b69a6ff Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Thu, 19 Jan 2017 10:32:06 +0100 Subject: [PATCH] fix #364 - detect 2 cases where CT vars used in type of declaration --- src/analysis/unused.d | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/analysis/unused.d b/src/analysis/unused.d index 5c9fd38..41ee57e 100644 --- a/src/analysis/unused.d +++ b/src/analysis/unused.d @@ -262,6 +262,26 @@ class UnusedVariableCheck : BaseAnalyzer variableDeclaration.accept(this); } + override void visit(const Type2 tp) + { + if (tp.symbol && tp.symbol.identifierOrTemplateChain && + tp.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances) + { + const IdentifierOrTemplateInstance idt = tp.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances[0]; + if (idt.identifier != tok!"") + variableUsed(idt.identifier.text); + else if (idt.templateInstance) + { + const TemplateInstance ti = idt.templateInstance; + if (ti.identifier != tok!"") + variableUsed(idt.templateInstance.identifier.text); + if (ti.templateArguments && ti.templateArguments.templateSingleArgument) + variableUsed(ti.templateArguments.templateSingleArgument.token.text); + } + } + tp.accept(this); + } + override void visit(const AutoDeclaration autoDeclaration) { foreach (t; autoDeclaration.parts.map!(a => a.identifier)) @@ -453,6 +473,22 @@ unittest return a; } + // Issue 364 + void test364_1() + { + enum s = 8; + immutable t = 2; + int[s][t] a; + a[0][0] = 1; + } + + void test364_2() + { + enum s = 8; + alias a = e!s; + a = 1; + } + }c, sac); stderr.writeln("Unittest for UnusedVariableCheck passed."); }