What is 'scope' in function parameter?
Sobaya
sobaya007 at gmail.com
Tue Dec 26 12:35:37 UTC 2017
On Tuesday, 26 December 2017 at 00:17:33 UTC, Mike Franklin wrote:
> After a few hours trying to figure out why the compiler didn't
> catch this, I finally figured it out. You have to add `@safe`.
>
> import std.stdio;
>
> int[] x;
>
> void func(scope int[] a) @safe
> {
> x = a;
> }
>
> void main() @safe {
> func([0,1,2]);
> writeln(x);
> }
>
> This is one of the things really ticks me off about D; it has
> all the wrong defaults.
>
> At a minimum, the documentation needs clarification. I
> encourage you to file a bug report against the documentation
> at http://issues.dlang.org/
>
> Mike
Oh! Surely adding @safe makes the expected behavior.
According to your advice, I try to post a bug report.
Thanks!
Sobaya
More information about the Digitalmars-d-learn
mailing list