DIP1000: The return of 'Extend Return Scope Semantics'
ag0aep6g
anonymous at example.com
Sun Jun 13 07:50:50 UTC 2021
On 13.06.21 04:58, Walter Bright wrote:
> You're right. @system then.
Even an @system function must obey the spec (as long as it's called
correctly). An @system `move` still wouldn't be allowed to do `target =
source;` when `source` is `scope`.
A way forward could be leaving `scope` off:
----
void move(ref int* source, ref int* target) @safe
{
target = source; /* ok now */
}
----
Then one has to use @trusted when calling `move` one `scope` things:
----
void main() @safe
{
int* source1;
int* target1;
move(source1, target1); /* non-scope things just work */
int local;
int* source2 = &local;
() @trusted { /* scope things need @trusted */
scope int* target2;
move(source2, target2);
} ();
}
----
As always, applying @trusted correctly is hard and prone to errors.
If you don't want to change the language, it seems to me that replacing
`move` with a function that has the parameters swapped is the way to go.
More information about the Digitalmars-d
mailing list