Skip to content

Commit

Permalink
Merge pull request #7120 from tgehr/fix17807
Browse files Browse the repository at this point in the history
fix Issue 17807 - Spurious dead code warnings on enum and static variables.
  • Loading branch information
WalterBright committed Sep 15, 2017
2 parents 365e392 + e606297 commit 891b53a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/ddmd/expression.d
Expand Up @@ -3594,6 +3594,11 @@ extern (C++) abstract class Expression : RootObject
return .op_overload(this, sc);
}

bool hasCode()
{
return true;
}

void accept(Visitor v)
{
v.visit(this);
Expand Down Expand Up @@ -5713,6 +5718,15 @@ extern (C++) final class DeclarationExp : Expression
return new DeclarationExp(loc, declaration.syntaxCopy(null));
}

override bool hasCode()
{
if (auto vd = declaration.isVarDeclaration())
{
return !(vd.storage_class & (STCmanifest | STCstatic));
}
return false;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down
7 changes: 7 additions & 0 deletions src/ddmd/expression.h
Expand Up @@ -214,6 +214,11 @@ class Expression : public RootObject
return ::op_overload(this, sc);
}

virtual bool hasCode()
{
return true;
}

virtual void accept(Visitor *v) { v->visit(this); }
};

Expand Down Expand Up @@ -612,6 +617,8 @@ class DeclarationExp : public Expression

Expression *syntaxCopy();

bool hasCode();

void accept(Visitor *v) { v->visit(this); }
};

Expand Down
5 changes: 4 additions & 1 deletion src/ddmd/statement.d
Expand Up @@ -272,7 +272,10 @@ extern (C++) abstract class Statement : RootObject

override void visit(ExpStatement s)
{
stop = s.exp !is null;
if (s.exp !is null)
{
stop = s.exp.hasCode();
}
}

override void visit(CompoundStatement s)
Expand Down
17 changes: 17 additions & 0 deletions test/compilable/test17807.d
@@ -0,0 +1,17 @@
// REQUIRED_ARGS: -o- -w

int bug17807(){
int y=0;
Lswitch: switch(2){
{ case 0: break; }
enum x=0;
struct S{ enum x=0; }
int foo(){
return 0;
}
default: y=x+S.x+foo();
static foreach(i;1..5)
case i: break Lswitch;
}
return y;
}

0 comments on commit 891b53a

Please sign in to comment.