Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/escape.d
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ private void escapeByValue(Expression e, EscapeByResults* er)
*/
private void escapeByRef(Expression e, EscapeByResults* er)
{
//printf("[%s] escapeByRef, e: %s\n", e.loc.toChars(), e.toChars());
extern (C++) final class EscapeRefVisitor : Visitor
{
alias visit = super.visit;
Expand Down
22 changes: 22 additions & 0 deletions src/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -10749,6 +10749,28 @@ extern (C++) final class AddrExp : UnaExp
}
}
}
else if (e1.op == TOKindex)
{
/* For:
* int[3] a;
* &a[i]
* check 'a' the same as for a regular variable
*/
IndexExp ei = cast(IndexExp)e1;
Type tyi = ei.e1.type.toBasetype();
if (tyi.ty == Tsarray && ei.e1.op == TOKvar)
{
VarExp ve = cast(VarExp)ei.e1;
VarDeclaration v = ve.var.isVarDeclaration();
if (v)
{
if (!checkAddressVar(v))
return new ErrorExp();

ve.checkPurity(sc, v);
}
}
}
else if (wasCond)
{
/* a ? b : c was transformed to *(a ? &b : &c), but we still
Expand Down
22 changes: 22 additions & 0 deletions test/fail_compilation/retscope.d
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,25 @@ int* bar10( scope int** ptr ) @safe
return *ptr;
}

/******************************************/

/*
TEST_OUTPUT:
---
fail_compilation/retscope.d(343): Error: cannot take address of scope local aa in @safe function escape11
---
*/

int* escape11() @safe
{
int i;
int*[3] aa = [ &i, null, null ];
return bar11(&aa[0]);
}

int* bar11(scope int** x) @safe
{
return foo11(*x);
}

int* foo11(int* x) @safe { return x; }