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
19 changes: 11 additions & 8 deletions src/escape.d
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ bool checkEscapeRef(Scope* sc, Expression e, bool gag)

private bool checkEscapeImpl(Scope* sc, Expression e, bool refs, bool gag)
{
//printf("[%s] checkEscapeImpl, e = %s\n", e.loc.toChars(), e.toChars());
EscapeByResults er;

if (refs)
Expand All @@ -433,19 +434,21 @@ private bool checkEscapeImpl(Scope* sc, Expression e, bool refs, bool gag)

Dsymbol p = v.toParent2();

if ((v.isScope() || (v.storage_class & STCmaybescope)) &&
!(v.storage_class & STCreturn) &&
v.isParameter() &&
sc.func.flags & FUNCFLAGreturnInprocess &&
p == sc.func)
{
inferReturn(sc.func, v); // infer addition of 'return'
continue;
}

if (v.isScope())
{
if (v.storage_class & STCreturn)
continue;

if (v.isParameter())
{
if (sc.func.flags & FUNCFLAGreturnInprocess && p == sc.func)
{
inferReturn(sc.func, v); // infer addition of 'return'
continue;
}
}
if (sc._module && sc._module.isRoot() &&
/* This case comes up when the ReturnStatement of a __foreachbody is
* checked for escapes by the caller of __foreachbody. Skip it.
Expand Down
20 changes: 20 additions & 0 deletions test/fail_compilation/retscope.d
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,23 @@ void escape5() @safe
pp = &p; // error
}

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

/*
TEST_OUTPUT:
---
fail_compilation/retscope.d(287): Error: escaping reference to local variable b
---
*/

@safe int* foo6()(int* arg)
{
return arg;
}

int* escape6() @safe
{
int b;
return foo6(&b);
}