Skip to content

Commit

Permalink
Merge pull request #10640 from WalterBright/fix20416
Browse files Browse the repository at this point in the history
fix Issue 20416 - [Regression 2.073.2] compiler complains about escap…
  • Loading branch information
thewilsonator committed Dec 7, 2019
2 parents feef16d + a1d82c6 commit 9b0cd0d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/dmd/escape.d
Expand Up @@ -1651,7 +1651,19 @@ private void escapeByValue(Expression e, EscapeByResults* er)
if ((stc & (STC.scope_)) && (stc & STC.return_))
arg.accept(this);
else if ((stc & (STC.ref_)) && (stc & STC.return_))
escapeByRef(arg, er);
{
if (tf.isref)
{
/* Treat:
* ref P foo(return ref P p)
* as:
* p;
*/
arg.accept(this);
}
else
escapeByRef(arg, er);
}
}
}
}
Expand All @@ -1666,7 +1678,19 @@ private void escapeByValue(Expression e, EscapeByResults* er)
if (ad.isClassDeclaration() || tf.isscope) // this is 'return scope'
dve.e1.accept(this);
else if (ad.isStructDeclaration()) // this is 'return ref'
escapeByRef(dve.e1, er);
{
if (tf.isref)
{
/* Treat calling:
* struct S { ref S foo() return; }
* as:
* this;
*/
dve.e1.accept(this);
}
else
escapeByRef(dve.e1, er);
}
}
else if (dve.var.storage_class & STC.return_ || tf.isreturn)
{
Expand Down
36 changes: 36 additions & 0 deletions test/compilable/fix20416.d
@@ -0,0 +1,36 @@
/* REQUIRED_ARGS: -preview=dip1000
*/

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

// https://issues.dlang.org/show_bug.cgi?id=20416

alias P = int*;

ref P foo(return ref P);

P bar()
{
P result;
return foo(result);
}


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

// https://issues.dlang.org/show_bug.cgi?id=20416


struct S
{
string x;
ref S foo() return;
}


S bar2()
{
S result;
return result.foo();
}

0 comments on commit 9b0cd0d

Please sign in to comment.