Does scope not work on parameters?

Steven Schveighoffer schveiguy at gmail.com
Sun Feb 23 03:26:17 UTC 2020


On 2/22/20 10:01 PM, Russ wrote:
> Is there some newer feature I should be using?

scope escapes are only disallowed in @safe code.

Adding @safe: to the top of this file makes it not compile with a complaint:

Error: scope variable z assigned to non-scope b.foo

Which I think is what you expected.

As to why it happens without @safe, you may be managing your global 
variable carefully and ensuring it's unset by the time foo goes away. 
The compiler can't know.

Another reason to enable safe-by-default...

-Steve


More information about the Digitalmars-d-learn mailing list