diff --git a/src/dmd/escape.d b/src/dmd/escape.d index e7600656c35c..545cef70ed1a 100644 --- a/src/dmd/escape.d +++ b/src/dmd/escape.d @@ -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_)) diff --git a/test/compilable/scope.d b/test/compilable/scope.d index 71247da634e2..20c79fadd309 100644 --- a/test/compilable/scope.d +++ b/test/compilable/scope.d @@ -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); +}