Skip to content

Commit

Permalink
DIP25: foreach ref variables
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jan 28, 2015
1 parent fa296e9 commit 9f20a78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/escape.c
Expand Up @@ -274,7 +274,7 @@ bool checkEscapeRef(Scope *sc, Expression *e, bool gag)
}

if (global.params.useDIP25 &&
(v->storage_class & (STCref | STCout)) && !(v->storage_class & STCreturn))
(v->storage_class & (STCref | STCout)) && !(v->storage_class & (STCreturn | STCforeach)))
{
if (sc->func->flags & FUNCFLAGreturnInprocess)
{
Expand All @@ -293,12 +293,14 @@ bool checkEscapeRef(Scope *sc, Expression *e, bool gag)
else if (sc->module && sc->module->isRoot())
{
//printf("escaping reference to local ref variable %s\n", v->toChars());
//printf("storage class = x%llx\n", v->storage_class);
error(loc, "escaping reference to local ref variable %s", v);
}
return;
}

if ((v->storage_class & (STCref | STCtemp)) == (STCref | STCtemp) &&
if (v->storage_class & STCref &&
v->storage_class & (STCforeach | STCtemp) &&
v->init)
{
// (ref v = ex; ex)
Expand Down
11 changes: 11 additions & 0 deletions test/runnable/testscope2.d
Expand Up @@ -202,6 +202,17 @@ void test11()

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

int[10] a12;

int* foo12()
{
foreach (ref x; a12)
return &x;
return null;
}

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

void main()
{
test3();
Expand Down

0 comments on commit 9f20a78

Please sign in to comment.