Skip to content

Commit

Permalink
Merge pull request #5973 from WalterBright/fix16292
Browse files Browse the repository at this point in the history
fix Issue 16292 - [REG2.069] bogus Error: goto skips declaration of v…
  • Loading branch information
andralex committed Aug 5, 2016
2 parents 584d40b + 0e9a52f commit 970c687
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/declaration.d
Expand Up @@ -126,6 +126,7 @@ enum STCvolatile = (1L << 43); // destined for volatile in the back
enum STCreturn = (1L << 44); // 'return ref' for function parameters
enum STCautoref = (1L << 45); // Mark for the already deduced 'auto ref' parameter
enum STCinference = (1L << 46); // do attribute inference
enum STCexptemp = (1L << 47); // temporary variable that has lifetime restricted to an expression

enum STC_TYPECTOR = (STCconst | STCimmutable | STCshared | STCwild);
enum STC_FUNCATTR = (STCref | STCnothrow | STCnogc | STCpure | STCproperty | STCsafe | STCtrusted | STCsystem);
Expand Down
5 changes: 4 additions & 1 deletion src/expression.d
Expand Up @@ -2343,7 +2343,10 @@ extern (C++) Expression extractOpDollarSideEffect(Scope* sc, UnaExp ue)
* (ref __dop = e1, __dop).opIndex( ... __dop.opDollar ...)
* (ref __dop = e1, __dop).opSlice( ... __dop.opDollar ...)
*/
e1 = extractSideEffect(sc, "__dop", e0, e1);
e1 = extractSideEffect(sc, "__dop", e0, e1, false);
assert(e1.op == TOKvar);
VarExp ve = cast(VarExp)e1;
ve.var.storage_class |= STCexptemp; // lifetime limited to expression
}
ue.e1 = e1;
return e0;
Expand Down
4 changes: 4 additions & 0 deletions src/statement.d
Expand Up @@ -2590,6 +2590,10 @@ extern (C++) final class GotoStatement : Statement
{
// All good, the label's scope has no variables
}
else if (vd.storage_class & STCexptemp)
{
// Lifetime ends at end of expression, so no issue with skipping the statement
}
else if (vd.ident == Id.withSym)
{
error("goto skips declaration of with temporary at %s", vd.loc.toChars());
Expand Down
19 changes: 19 additions & 0 deletions test/compilable/test16292.d
@@ -0,0 +1,19 @@
/* PERMUTE_ARGS:
*/
// https://issues.dlang.org/show_bug.cgi?id=16292

void main()
{
goto label;
if (makeS()[0])
{
label:
}
}

S makeS() { return S(); }

struct S
{
int opIndex(size_t i) { return 0; }
}

0 comments on commit 970c687

Please sign in to comment.