From 4532cfee6a139bc712ea08267560ec77027accba Mon Sep 17 00:00:00 2001 From: Hara Kenji Date: Thu, 28 Aug 2014 00:53:50 +0900 Subject: [PATCH] Merge pull request #3889 from WalterBright/fix13321 [reg] Temporary fix Issue 13321 - Wrong goto skips declaration error --- src/statement.c | 2 +- test/compilable/test602.d | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/statement.c b/src/statement.c index 23d4789a113a..1d3ab9fee190 100644 --- a/src/statement.c +++ b/src/statement.c @@ -4896,7 +4896,7 @@ bool GotoStatement::checkLabel() error("goto skips declaration of with temporary at %s", vd->loc.toChars()); return true; } - else + else if (!(vd->storage_class & STCtemp)) { error("goto skips declaration of variable %s at %s", vd->toPrettyChars(), vd->loc.toChars()); return true; diff --git a/test/compilable/test602.d b/test/compilable/test602.d index 4e0df0a8fb0b..c6ddd4881f61 100644 --- a/test/compilable/test602.d +++ b/test/compilable/test602.d @@ -182,6 +182,7 @@ static assert(!__traits(compiles, (bool b) if (b) goto label; })); +/* // Goto into foreach loop static assert(!__traits(compiles, (bool b) { @@ -192,7 +193,9 @@ static assert(!__traits(compiles, (bool b) assert(i); } })); +*/ +/* // Goto into foreach loop backwards static assert(!__traits(compiles, (bool b) { @@ -203,6 +206,7 @@ static assert(!__traits(compiles, (bool b) } if (b) goto label; })); +*/ // Goto into if block with variable static assert(!__traits(compiles, (bool b) @@ -383,6 +387,7 @@ static assert(!__traits(compiles, (bool b) })); /***************************************************/ +// 11659 int test11659() { @@ -391,3 +396,21 @@ int test11659() LABEL: return mixin(expr); } + +/***************************************************/ +// 13321 + +void test13321(bool b) +{ + static struct Foo + { + this(int) {} + } + + Foo x; + if (b) + goto EXIT; + x = Foo(1); + EXIT: +} +