What is the state of scope function parameter?
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 29 06:03:00 PDT 2017
On Wednesday, 29 March 2017 at 05:15:33 UTC, Ali Çehreli wrote:
> scope: references in the parameter cannot be escaped
> (e.g. assigned to a global variable). Ignored for
> parameters with no references
>
> However, it doesn't behave that way. For example, my example
> here currently is a lie because there is no compilation error
> with 2.073.2:
If you break the rules, even if the compiler doesn't actually
catch it, you are still writing illegal code and subject to
runtime undefined behavior and/or compilation errors in future
versions.
The compiler DOES use the scope attribute to optimize out heap
allocations in some cases now, which means if you use in
improperly you are liable for memory corruption.
So maybe it should say "must not" instead of "cannot" since you
CAN, it is just broken if you do.
More information about the Digitalmars-d-learn
mailing list