Skip to content

Commit

Permalink
Fix Issue 16578 - bogus deprecation - switch skips declaration of var…
Browse files Browse the repository at this point in the history
…iable
  • Loading branch information
JinShil committed Feb 23, 2018
1 parent 9d7403f commit 8515ae6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/dmd/statement.d
Expand Up @@ -1610,6 +1610,11 @@ extern (C++) final class SwitchStatement : Statement
// All good, the label's scope has no variables
return false;
}
else if (vd.storage_class & STC.temp)
{
// Lifetime ends at end of expression, so no issue with skipping the statement
return false;
}
else if (vd.ident == Id.withSym)
{
deprecation("`switch` skips declaration of `with` temporary at %s", vd.loc.toChars());
Expand Down
16 changes: 16 additions & 0 deletions test/compilable/test16578a.d
@@ -0,0 +1,16 @@
// REQUIRED_ARGS: -debug

// https://issues.dlang.org/show_bug.cgi?id=16578

string[string] opts;

void main()
{
string arg;
switch (arg)
{
case "-f": opts["fore"] = ""; break;
debug { case "-throw": opts["throw"] = ""; break; }
default:
}
}
16 changes: 16 additions & 0 deletions test/compilable/test16578b.d
@@ -0,0 +1,16 @@
// https://issues.dlang.org/show_bug.cgi?id=16578

void main()
{
string[string] opts;
switch (2)
{
case 0:
opts["a"] = "";
{
case 1:
break;
}
default:
}
}

0 comments on commit 8515ae6

Please sign in to comment.