Skip to content

Commit

Permalink
fix issue 20682 - [DIP1000] wrong error: scope variable may not be co…
Browse files Browse the repository at this point in the history
…pied into allocated memory
  • Loading branch information
aG0aep6G committed Mar 18, 2020
1 parent 1499a0d commit 6346988
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/dmd/escape.d
Expand Up @@ -1665,6 +1665,9 @@ void escapeByValue(Expression e, EscapeByResults* er, bool live = false)
{
Parameter p = tf.parameterList[i - j];
const stc = tf.parameterStorageClass(null, p);
auto returnType = tf.next;
if (!returnType.hasPointers())
continue;
if ((stc & (STC.scope_)) && (stc & STC.return_))
arg.accept(this);
else if ((stc & (STC.ref_)) && (stc & STC.return_))
Expand Down
19 changes: 19 additions & 0 deletions test/compilable/scope.d
Expand Up @@ -94,3 +94,22 @@ void test(scope ref D d) @safe
D[] da;
da ~= D(d.pos, null);
}

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

int f1_20682(return scope ref D d) @safe
{
return d.pos;
}

ref int f2_20682(return scope ref D d) @safe
{
return d.pos;
}

void test_20682(scope ref D d) @safe
{
int[] a;
a ~= f1_20682(d);
a ~= f2_20682(d);
}

0 comments on commit 6346988

Please sign in to comment.